{"id":13413419,"url":"https://github.com/rafaeljesus/rabbus","last_synced_at":"2025-04-27T20:32:46.568Z","repository":{"id":57480563,"uuid":"90520062","full_name":"rafaeljesus/rabbus","owner":"rafaeljesus","description":"A tiny wrapper over amqp exchanges and queues 🚌 ✨","archived":false,"fork":false,"pushed_at":"2019-07-23T10:48:01.000Z","size":140,"stargazers_count":98,"open_issues_count":6,"forks_count":24,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-26T05:48:08.731Z","etag":null,"topics":["amqp","event-driven","eventbus","golang","microservices","rabbitmq","resilience"],"latest_commit_sha":null,"homepage":"","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/rafaeljesus.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}},"created_at":"2017-05-07T08:51:11.000Z","updated_at":"2025-04-08T17:38:40.000Z","dependencies_parsed_at":"2022-09-26T17:41:14.082Z","dependency_job_id":null,"html_url":"https://github.com/rafaeljesus/rabbus","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaeljesus%2Frabbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaeljesus%2Frabbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaeljesus%2Frabbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaeljesus%2Frabbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafaeljesus","download_url":"https://codeload.github.com/rafaeljesus/rabbus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251204633,"owners_count":21552257,"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":["amqp","event-driven","eventbus","golang","microservices","rabbitmq","resilience"],"created_at":"2024-07-30T20:01:39.935Z","updated_at":"2025-04-27T20:32:46.293Z","avatar_url":"https://github.com/rafaeljesus.png","language":"Go","readme":"## Rabbus 🚌 ✨\n\n* A tiny wrapper over [amqp](https://github.com/streadway/amqp) exchanges and queues.\n* In memory retries with exponential backoff for sending messages.\n* Protect producer calls with [circuit breaker](https://github.com/sony/gobreaker).\n* Automatic reconnect to RabbitMQ broker when connection is lost.\n* Go channel API.\n\n## Installation\n```bash\ngo get -u github.com/rafaeljesus/rabbus\n```\n\n## Usage\nThe rabbus package exposes an interface for emitting and listening RabbitMQ messages.\n\n### Emit\n```go\nimport (\n\t\"context\"\n\t\"time\"\n\n\t\"github.com/rafaeljesus/rabbus\"\n)\n\nfunc main() {\n\ttimeout := time.After(time.Second * 3)\n\tcbStateChangeFunc := func(name, from, to string) {\n\t\t// do something when state is changed\n\t}\n\tr, err := rabbus.New(\n\t\trabbusDsn,\n\t\trabbus.Durable(true),\n\t\trabbus.Attempts(5),\n\t\trabbus.Sleep(time.Second*2),\n\t\trabbus.Threshold(3),\n\t\trabbus.OnStateChange(cbStateChangeFunc),\n\t)\n\tif err != nil {\n\t\t// handle error\n\t}\n\n\tdefer func(r Rabbus) {\n\t\tif err := r.Close(); err != nil {\n\t\t\t// handle error\n\t\t}\n\t}(r)\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tgo r.Run(ctx)\n\n\tmsg := rabbus.Message{\n\t\tExchange: \"test_ex\",\n\t\tKind:     \"topic\",\n\t\tKey:      \"test_key\",\n\t\tPayload:  []byte(`foo`),\n\t}\n\n\tr.EmitAsync() \u003c- msg\n\n\tfor {\n\t\tselect {\n\t\tcase \u003c-r.EmitOk():\n\t\t\t// message was sent\n\t\tcase \u003c-r.EmitErr():\n\t\t\t// failed to send message\n\t\tcase \u003c-timeout:\n\t\t\t// handle timeout error\n\t\t}\n\t}\n}\n```\n\n### Listen\n```go\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"time\"\n\n\t\"github.com/rafaeljesus/rabbus\"\n)\n\nfunc main() {\n\ttimeout := time.After(time.Second * 3)\n\tcbStateChangeFunc := func(name, from, to string) {\n\t\t// do something when state is changed\n\t}\n\tr, err := rabbus.New(\n\t\trabbusDsn,\n\t\trabbus.Durable(true),\n\t\trabbus.Attempts(5),\n\t\trabbus.Sleep(time.Second*2),\n\t\trabbus.Threshold(3),\n\t\trabbus.OnStateChange(cbStateChangeFunc),\n\t)\n\tif err != nil {\n\t\t// handle error\n\t}\n\n\tdefer func(r Rabbus) {\n\t\tif err := r.Close(); err != nil {\n\t\t\t// handle error\n\t\t}\n\t}(r)\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tgo r.Run(ctx)\n\n\tmessages, err := r.Listen(rabbus.ListenConfig{\n\t\tExchange:    \"events_ex\",\n\t\tKind:        \"topic\",\n\t\tKey:         \"events_key\",\n\t\tQueue:       \"events_q\",\n\t\tDeclareArgs: rabbus.NewDeclareArgs().WithMessageTTL(15 * time.Minute).With(\"foo\", \"bar\"),\n\t\tBindArgs:    rabbus.NewBindArgs().With(\"baz\", \"qux\"),\n\t})\n\tif err != nil {\n\t\t// handle errors during adding listener\n\t}\n\tdefer close(messages)\n\n\tgo func(messages chan ConsumerMessage) {\n\t\tfor m := range messages {\n\t\t\tm.Ack(false)\n\t\t}\n\t}(messages)\n}\n```\n\n## Contributing\n- Fork it\n- Create your feature branch (`git checkout -b my-new-feature`)\n- Commit your changes (`git commit -am 'Add some feature'`)\n- Push to the branch (`git push origin my-new-feature`)\n- Create new Pull Request\n\n## Badges\n\n[![Build Status](https://circleci.com/gh/rafaeljesus/rabbus.svg?style=svg)](https://circleci.com/gh/rafaeljesus/rabbus)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rafaeljesus/rabbus)](https://goreportcard.com/report/github.com/rafaeljesus/rabbus)\n[![Go Doc](https://godoc.org/github.com/rafaeljesus/rabbus?status.svg)](https://godoc.org/github.com/rafaeljesus/rabbus)\n\n---\n\n\u003e GitHub [@rafaeljesus](https://github.com/rafaeljesus) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e Medium [@_jesus_rafael](https://medium.com/@_jesus_rafael) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e Twitter [@_jesus_rafael](https://twitter.com/_jesus_rafael)\n","funding_links":[],"categories":["消息","Development","Messaging","消息系统","Relational Databases","消息传递","机器学习"],"sub_categories":["Advanced Console UIs","Go Libraries","检索及分析资料库","SQL 查询语句构建库","Search and Analytic Databases","交流"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaeljesus%2Frabbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafaeljesus%2Frabbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaeljesus%2Frabbus/lists"}