{"id":20252602,"url":"https://github.com/streamdal/rabbit","last_synced_at":"2025-08-30T09:33:02.920Z","repository":{"id":45403362,"uuid":"300774096","full_name":"streamdal/rabbit","owner":"streamdal","description":"RabbitMQ wrapper for steadway/amqp that supports auto-reconnects","archived":false,"fork":false,"pushed_at":"2024-12-02T21:37:47.000Z","size":102,"stargazers_count":45,"open_issues_count":2,"forks_count":9,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-08-10T06:36:26.330Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streamdal.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,"zenodo":null}},"created_at":"2020-10-03T01:44:59.000Z","updated_at":"2024-12-02T21:36:44.000Z","dependencies_parsed_at":"2023-09-03T03:13:18.999Z","dependency_job_id":"eeb133e2-8d0b-4090-a451-7648f3ff7923","html_url":"https://github.com/streamdal/rabbit","commit_stats":null,"previous_names":["batchcorp/rabbit"],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/streamdal/rabbit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Frabbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Frabbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Frabbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Frabbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streamdal","download_url":"https://codeload.github.com/streamdal/rabbit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Frabbit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272833278,"owners_count":25000870,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-11-14T10:17:32.368Z","updated_at":"2025-08-30T09:33:02.891Z","avatar_url":"https://github.com/streamdal.png","language":"Go","readme":"rabbit\n======\n[![](https://godoc.org/github.com/streamdal/rabbit?status.svg)](http://godoc.org/github.com/streamdal/rabbit) [![Master build status](https://github.com/streamdal/rabbit/workflows/main/badge.svg)](https://github.com/streamdal/rabbit/actions) [![Go Report Card](https://goreportcard.com/badge/github.com/streamdal/rabbit)](https://goreportcard.com/report/github.com/streamdal/rabbit)\n\nA RabbitMQ wrapper lib around ~[streadway/amqp](https://github.com/streadway/amqp)~ [rabbitmq/amqp091-go](https://github.com/rabbitmq/amqp091-go) \nwith some bells and whistles.\n\nNOTE: `streadway/amqp` is no longer maintained and RabbitMQ team have forked `streadway/amqp` and created `rabbitmq/amqp091-go`. You can read about this change [here](https://github.com/streadway/amqp/issues/497). This library uses `rabbitmq/amqp091-go`.\n\n* Support for auto-reconnect\n* Support for context (ie. cancel/timeout)\n* Support for using multiple binding keys\n* Support Producer, Consumer or both modes\n\n# Motivation\n\nWe (Streamdal, formerly Batch.sh), make heavy use of RabbitMQ - we use it as \nthe primary method for facilitating inter-service communication. Due to this, \nall services make use of RabbitMQ and are both publishers and consumers.\n\nWe wrote this lib to ensure that all of our services make use of Rabbit in a\nconsistent, predictable way AND are able to survive network blips.\n\n**NOTE**: This library works only with non-default exchanges. If you need support\nfor default exchange - open a PR!\n\n# Usage\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"  \n\n    \"github.com/streamdal/rabbit\"\n)\n\nfunc main() { \n    r, err := rabbit.New(\u0026rabbit.Options{\n        URL:          \"amqp://localhost\",\n        QueueName:    \"my-queue\",\n        ExchangeName: \"messages\",\n        BindingKeys:   []string{\"messages\"},\n    })\n    if err != nil {\n        log.Fatalf(\"unable to instantiate rabbit: %s\", err)\n    }\n    \n    routingKey := \"messages\"\n    data := []byte(\"pumpkins\")\n\n    // Publish something\n    if err := r.Publish(context.Background(), routingKey, data); err != nil {\n        log.Fatalf(\"unable to publish message: \")\n    }\n\n    // Consume once\n    if err := r.ConsumeOnce(nil, func(amqp.Delivery) error {\n        fmt.Printf(\"Received new message: %+v\\n\", msg)\n    }); err != nil {\n        log.Fatalf(\"unable to consume once: %s\", err),\n    }\n\n    var numReceived int\n\n    // Consume forever (blocks)\n    ctx, cancel := context.WithCancel(context.Background())\n\n    r.Consume(ctx, nil, func(msg amqp.Delivery) error {\n        fmt.Printf(\"Received new message: %+v\\n\", msg)\n        \n        numReceived++\n        \n        if numReceived \u003e 1 {\n            r.Stop()\n        }\n    })\n\n    // Or stop via ctx \n    r.Consume(..)\n    cancel()\n}\n```\n\n### Retry Policies\n\nYou can specify a retry policy for the consumer.\nA pre-made ACK retry policy is available in the library at `rp := rabbit.DefaultAckPolicy()`. This policy will retry\nacknowledgement unlimited times\n\nYou can also create a new policy using the `rabbit.NewRetryPolicy(maxAttempts, time.Millisecond * 200, time.Second, ...)` function.\n\nThe retry policy can then be passed to consume functions as an argument:\n\n```go\nconsumeFunc := func(msg amqp.Delivery) error {\n    fmt.Printf(\"Received new message: %+v\\n\", msg)\n    \n    numReceived++\n    \n    if numReceived \u003e 1 {\n            r.Stop()\n        }\n    }\n\nrp := rabbit.DefaultAckPolicy()\n\nr.Consume(ctx, nil, consumeFunc, rp)\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamdal%2Frabbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreamdal%2Frabbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamdal%2Frabbit/lists"}