{"id":13575586,"url":"https://github.com/wagslane/go-rabbitmq","last_synced_at":"2025-05-14T06:11:51.145Z","repository":{"id":38351094,"uuid":"345207371","full_name":"wagslane/go-rabbitmq","owner":"wagslane","description":"A wrapper of streadway/amqp that provides reconnection logic and sane defaults","archived":false,"fork":false,"pushed_at":"2024-12-16T20:02:45.000Z","size":339,"stargazers_count":862,"open_issues_count":11,"forks_count":135,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-13T22:18:26.679Z","etag":null,"topics":["go","golang","golang-library","rabbit","rabbitmq","rabbitmq-client","rabbitmq-consumer","rabbitmq-producer"],"latest_commit_sha":null,"homepage":"https://blog.boot.dev/golang/connecting-to-rabbitmq-in-golang-easy/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wagslane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-03-06T22:19:14.000Z","updated_at":"2025-04-13T16:07:40.000Z","dependencies_parsed_at":"2024-04-08T20:10:24.163Z","dependency_job_id":"bb406f76-22be-4450-9bf3-a1aef8eb9c3e","html_url":"https://github.com/wagslane/go-rabbitmq","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagslane%2Fgo-rabbitmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagslane%2Fgo-rabbitmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagslane%2Fgo-rabbitmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wagslane%2Fgo-rabbitmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wagslane","download_url":"https://codeload.github.com/wagslane/go-rabbitmq/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254080009,"owners_count":22011309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["go","golang","golang-library","rabbit","rabbitmq","rabbitmq-client","rabbitmq-consumer","rabbitmq-producer"],"created_at":"2024-08-01T15:01:02.380Z","updated_at":"2025-05-14T06:11:51.124Z","avatar_url":"https://github.com/wagslane.png","language":"Go","funding_links":[],"categories":["Go","GO"],"sub_categories":["Manuals"],"readme":"# go-rabbitmq\n\nA wrapper of [rabbitmq/amqp091-go](https://github.com/rabbitmq/amqp091-go) that provides reconnection logic and sane defaults. Hit the project with a star if you find it useful ⭐\n\nSupported by [Boot.dev](https://boot.dev). If you'd like to learn about RabbitMQ and Go, you can check out [my course here](https://www.boot.dev/learn/learn-pub-sub).\n\n[![](https://godoc.org/github.com/wagslane/go-rabbitmq?status.svg)](https://godoc.org/github.com/wagslane/go-rabbitmq)![Deploy](https://github.com/wagslane/go-rabbitmq/workflows/Tests/badge.svg)\n\n## Motivation\n\n[Streadway's AMQP](https://github.com/rabbitmq/amqp091-go) library is currently the most robust and well-supported Go client I'm aware of. It's a fantastic option and I recommend starting there and seeing if it fulfills your needs. Their project has made an effort to stay within the scope of the AMQP protocol, as such, no reconnection logic and few ease-of-use abstractions are provided.\n\n### Goal\n\nThe goal with `go-rabbitmq` is to provide *most* (but not all) of the nitty-gritty functionality of Streadway's AMQP, but to make it easier to work with via a higher-level API. `go-rabbitmq` is also built specifically for Rabbit, not for the AMQP protocol. In particular, we want:\n\n* Automatic reconnection\n* Multithreaded consumers via a handler function\n* Reasonable defaults\n* Flow control handling\n* TCP block handling\n\n## ⚙️ Installation\n\nInside a Go module:\n\n```bash\ngo get github.com/wagslane/go-rabbitmq\n```\n\n## 🚀 Quick Start Consumer\n\nTake note of the optional `options` parameters after the queue name. The *queue* will be declared automatically, but the *exchange* will not. You'll also *probably* want to bind to at least one routing key.\n\n```go\nconn, err := rabbitmq.NewConn(\n\t\"amqp://guest:guest@localhost\",\n\trabbitmq.WithConnectionOptionsLogging,\n)\nif err != nil {\n\tlog.Fatal(err)\n}\ndefer conn.Close()\n\nconsumer, err := rabbitmq.NewConsumer(\n\tconn,\n\t\"my_queue\",\n\trabbitmq.WithConsumerOptionsRoutingKey(\"my_routing_key\"),\n\trabbitmq.WithConsumerOptionsExchangeName(\"events\"),\n\trabbitmq.WithConsumerOptionsExchangeDeclare,\n)\nif err != nil {\n\tlog.Fatal(err)\n}\ndefer consumer.Close()\n\nerr = consumer.Run(func(d rabbitmq.Delivery) rabbitmq.Action {\n\tlog.Printf(\"consumed: %v\", string(d.Body))\n\t// rabbitmq.Ack, rabbitmq.NackDiscard, rabbitmq.NackRequeue\n\treturn rabbitmq.Ack\n})\nif err != nil {\n\tlog.Fatal(err)\n}\n```\n\n## 🚀 Quick Start Publisher\n\nThe exchange is not declared by default, that's why I recommend using the following options.\n```go\nconn, err := rabbitmq.NewConn(\n\t\"amqp://guest:guest@localhost\",\n\trabbitmq.WithConnectionOptionsLogging,\n)\nif err != nil {\n\tlog.Fatal(err)\n}\ndefer conn.Close()\n\npublisher, err := rabbitmq.NewPublisher(\n\tconn,\n\trabbitmq.WithPublisherOptionsLogging,\n\trabbitmq.WithPublisherOptionsExchangeName(\"events\"),\n\trabbitmq.WithPublisherOptionsExchangeDeclare,\n)\nif err != nil {\n\tlog.Fatal(err)\n}\ndefer publisher.Close()\n\nerr = publisher.Publish(\n\t[]byte(\"hello, world\"),\n\t[]string{\"my_routing_key\"},\n\trabbitmq.WithPublishOptionsContentType(\"application/json\"),\n\trabbitmq.WithPublishOptionsExchange(\"events\"),\n)\nif err != nil {\n\tlog.Println(err)\n}\n```\n\n## Other usage examples\n\nSee the [examples](examples) directory for more ideas.\n\n## Options and configuring\n\n* By default, queues are declared if they didn't already exist by new consumers\n* By default, routing-key bindings are declared by consumers if you're using `WithConsumerOptionsRoutingKey`\n* By default, exchanges are *not* declared by publishers or consumers if they don't already exist, hence `WithPublisherOptionsExchangeDeclare` and `WithConsumerOptionsExchangeDeclare`.\n\nRead up on all the options in the GoDoc, there are quite a few of them. I try to pick sane and simple defaults.\n\n## Closing and resources\n\nClose your publishers and consumers when you're done with them and do *not* attempt to reuse them. Only close the connection itself once you've closed all associated publishers and consumers.\n\n## Stability\n\nNote that the API is currently in `v0`. I don't plan on huge changes, but there may be some small breaking changes before we hit `v1`.\n\n## Integration testing\n\nBy setting `ENABLE_DOCKER_INTEGRATION_TESTS=TRUE` during `go test -v ./...`, the integration tests will run. These launch a rabbitmq container in the local Docker daemon and test some publish/consume actions.\n\nSee [integration_test.go](integration_test.go).\n\n## 💬 Contact\n\n[![Twitter Follow](https://img.shields.io/twitter/follow/wagslane.svg?label=Follow%20Wagslane\u0026style=social)](https://twitter.com/intent/follow?screen_name=wagslane)\n\nSubmit an issue here on GitHub\n\n## Transient Dependencies\n\nMy goal is to keep dependencies limited to 1, [github.com/rabbitmq/amqp091-go](https://github.com/rabbitmq/amqp091-go).\n\n## 👏 Contributing\n\nI would love your help! Contribute by forking the repo and opening pull requests. Please ensure that your code passes the existing tests and linting, and write tests to test your changes if applicable.\n\nAll pull requests should be submitted to the `main` branch.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwagslane%2Fgo-rabbitmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwagslane%2Fgo-rabbitmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwagslane%2Fgo-rabbitmq/lists"}