{"id":24784133,"url":"https://github.com/mazezen/mqdo","last_synced_at":"2026-02-15T18:32:14.245Z","repository":{"id":135942984,"uuid":"517973055","full_name":"mazezen/mqdo","owner":"mazezen","description":"About Golang operation based on amqp0.9.1 rrabbmitmq","archived":false,"fork":false,"pushed_at":"2024-12-21T03:40:10.000Z","size":83,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-12T08:31:42.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mazezen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-26T08:17:59.000Z","updated_at":"2024-12-21T03:40:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"a448cbe5-f424-40f0-b8d4-dbfd8b2b5984","html_url":"https://github.com/mazezen/mqdo","commit_stats":null,"previous_names":["jeffpek/go-rabbitmq-tutorial","jeffcail/go-rabbitmq-tutorial","jeffcail/mqdo","mazezen/mqdo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mazezen/mqdo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazezen%2Fmqdo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazezen%2Fmqdo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazezen%2Fmqdo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazezen%2Fmqdo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazezen","download_url":"https://codeload.github.com/mazezen/mqdo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazezen%2Fmqdo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29486521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T15:33:17.885Z","status":"ssl_error","status_checked_at":"2026-02-15T15:32:53.698Z","response_time":118,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-29T12:46:24.075Z","updated_at":"2026-02-15T18:32:14.240Z","avatar_url":"https://github.com/mazezen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Go-rabbitmq-tutorial\n\n### 简介\n\nRabbitMQ 是一个实现了高级消息队列协议（AMQP）的开源消息代理中间件。 俗称消息队列\n\n\n\n### 基本组件\n\n\n* Connection 连接. 使用MQ之前需要建立连接\n\n* Producer 生产者\n* Consumer 消费者\n* Broker 服务器实例 管理消息和队列\n* Message 消息 由消息头和消息体组成\n* Queue 队列。消息的存放容器，先进先出\n* Exchange 交换器。 分发消息，将消息路由给服务器中的队列\n* Channel 信道\n* Virtual Host 虚拟主机\n\n\n### 官网\n\n\u003ca href=\"rabbitmq.com\" target=\"_blank\"\u003eRabbitmq官网\u003c/a\u003e\n\n\n\n### AMQP客户端\n\n\u003ca href=\"https://github.com/rabbitmq/amqp091-go\" target=\"_blank\"\u003eThe Go RabbitMQ client library \u003c/a\u003e\n\n\n\n### 安装\n\n```vim\ndocker run -it --rm --name go-rabbitmq-tutorial -p 5672:5672 -p 15672:15672 rabbitmq:3.10-management\n\nguest/guest\n```\n\n\n\n\n\n### 简单模式\n\n一个生产者，一个队列，一个消费者。Exchange不参与\n\n![hello-world](./hello-world.png)\n\n```shell\ncd hello-world\n\n# shell1\ngo run send.go\n\n# shell2\ngo run receive.go\n```\n\n\n\n\n\n\n\n### 工作模式\n\nWork Queue 工作队列。处理一些不需要立即执行，比较耗时的一些任务\n\nWork Queue 会将消息分发给不同的消费者进行处理（消费者接受到的消息是不同的），消费者接受消息的数量取决于自身处理消息的速度，可以不有效的提升性能\n\n场景： 短信、邮件等提醒\n\n![worker-queue](./worker-queue.png)\n\n```shell\ncd worker-queue\n\n# shell1\ngo run worker.go\n\n# shell2\ngo run new_task.go\n\n# 或者 开多个终端\n\n# shell1\ngo run worker.go\n\n# shell2\ngo run worker.go\n\n#shell3\ngo run new_task.go\n```\n\n\n\n\n\n### 发布订阅\n\nPublist/Subscribe 发布订阅\n\n生产者产生一条消息，将消息发送给交换器，交换器将消息推送给所有的消费者。消费者接受到的消息是相同的。\n\n场景： 开放平台  开发者订阅了某个开放平台的api之后，数据有变化就会自动获取到最新的数据\n\n\n\n![publish-subscribe](./publish-subscribe.png)\n\n```shell\ncd publish-subscribe\n\n# shell1\n# 如果你想保存日志文件\ngo run receive_log.go \u003e logs_from_rabbit.log\n\n# 如果你想再终端看到日志\ngo run receive_log.go\n\n# shell2\ngo run emit_log.go\n\n\n```\n\n\n\n\n\n### 路由模式\n\nRouting\n\n其实就是发布订阅模式的升级版。将不同消息通过路由key进行绑定，进入不同的队列，每个队列的处理不同的业务逻辑\n\n场景： 日志系统  重要的日志，有专门的队列消费处理\n\n![routing](./routing.png)\n\n```shell\ncd publish-subscribe\n\n# shell1\n# 如果你想保存日志文件\ngo run receive_logs_direct.go warning error \u003e logs_from_rabbit.log\n\n# 如果你想再终端看到日志\ngo run receive_logs_direct.go info warning error\n\n# shell2\ngo run emit_log_direct.go error \"Run. Run. Or it will explode.\"\n```\n\n\n\n\n\n### 主题订阅模式\n\nTopics\n\n在路由模式的基础上增加了通配符。可以惊醒Routing ket的模糊匹配，使得消息的分发更加灵活\n\n但是模糊匹配相对于路由模式来讲，效率可能比较低，实际中尽量采用路由模式\n\n通配符 ‘*’ ‘#’ *: 单个关键字 #: 多个关键字\n\n![topics](./topics.png)\n\n ```shell\ncd topics\n# shell1\ngo run receive_logs_topic.go \"#\"\n\n# shell2\ngo run receive_logs_topic.go \"kern.*\"\n\n# shell3\ngo run receive_logs_topic.go \"*.critical\"\n\n# shell4\ngo run receive_logs_topic.go \"kern.*\" \"*.critical\"\n\n# shell5\ngo run emit_log_topic.go \"kern.critical\" \"A critical kernel error\"\n\n ```\n\n\n\n\n\n### RPC同步通信\n\nMQ是一个异步通信的，也就是生产者发送消息之后，是不知道消费者的处理结果的（成功、失败、甚至都不知道消费者有没有处理这条消息）。\n\n有些时候，在开发中，生产者是需要知道消费者的处理结果，然后再进行下一步任务的处理。也就是同步调用。相当于RPC（Remote Procedure Call 远程过程调用）\n\n如下图所示，实际上有两个队列，client产生了消息之后，将消息放入队列，server端开始进行消费，消费后的结果也放入一个队列，被client处理. 整个过程，是一个线程阻塞的状态。影响性能，适用于特殊的业务场景需求。\n\n![rpc](./rpc.png)\n\n```shell\ncd rpc\n\n# shell1\ngo run rpc_server.go\n\n# shell2\ngo run rpc_client.go 40\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazezen%2Fmqdo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazezen%2Fmqdo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazezen%2Fmqdo/lists"}