{"id":22998227,"url":"https://github.com/uswitch/rabbitmq-worker","last_synced_at":"2025-04-02T13:24:12.033Z","repository":{"id":57714085,"uuid":"70601150","full_name":"uswitch/rabbitmq-worker","owner":"uswitch","description":"A small wrapper around the Langohr RabbitMQ client ","archived":false,"fork":false,"pushed_at":"2020-02-28T11:29:33.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-02-08T04:29:10.355Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Clojure","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/uswitch.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}},"created_at":"2016-10-11T14:20:07.000Z","updated_at":"2018-05-15T13:50:18.000Z","dependencies_parsed_at":"2022-09-26T21:31:11.741Z","dependency_job_id":null,"html_url":"https://github.com/uswitch/rabbitmq-worker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Frabbitmq-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Frabbitmq-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Frabbitmq-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Frabbitmq-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uswitch","download_url":"https://codeload.github.com/uswitch/rabbitmq-worker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246820809,"owners_count":20839304,"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":[],"created_at":"2024-12-15T06:12:13.663Z","updated_at":"2025-04-02T13:24:11.995Z","avatar_url":"https://github.com/uswitch.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rabbitmq-worker\n\nA Clojure library that wraps the excellent [Langohr](http://clojurerabbitmq.info/) library in order to hide the connecting to RabbitMQ,\n, consuming, acking/nacking of messages, publishing etc. For us this has been suprisingly error / confusion prone in projects that roll their own setup.\n\nThis library tries to be a \"Sugar-coated API for task queues that hides all the AMQP machinery from the developer\", [unlike the quite low level langohr](http://clojurerabbitmq.info/articles/getting_started.html#what-langohr-is-not). This library provides sensible defaults for most things, in an attempt to give a maximally simple interface to consume from queues and publish messages, so that you as a developer don't have to think as much.\n\n# Usage\n\n## Getting the library\nFor leiningen: \n```[uswitch/rabbitmq-worker \"0.3.1\"]```\n\n### Opening a connection\n\n```clojure\n(require '[rabbitmq-worker.worker :as worker])\n\n(worker/open-connection {:uri \"amqp://guest:guest@localhost:5672\"})\n\n(worker/open-connection {:host \"127.0.0.1\", :port 5672, :vhost \"/\", :password \"guest\", :username \"guest\"})\n```\n\n## Consuming messages\n\nFrom default exchange:\n\n```clojure\n(worker/consume connection \n                {:queue \"banana\"} \n                (fn [message] (println message)))\n```\n\nThe queue will be automatically declared with the defaults `:queue-auto-delete false`, `:queue-durable true`  and `:queue-exclusive false`.\n\nFrom another exchange:\n\n```clojure\n(worker/consume connection \n                {:exchange \"banana-exchange\" :queue \"fruits\"} \n                (fn [message] (println message)))\n```\n\nMessages that throw an error will be automatically pushed onto a queue named `{original-queue-name}-failed`. The failed queue is declared with `:failed-queue-auto-delete false`, `:failed-queue-durable  true` and `:failed-queue-exclusive false`.\n\nThe following map shows all the options supported if you need to configure more advanced consumers, but don't override unless you know what you're doing.\n\n```clojure\n{:queue                    String\n :queue-auto-delete        Boolean\n :queue-exclusive          Boolean\n :queue-durable            Boolean\n :queue-arguments          {:x-dead-letter-exchange String\n                            :x-dead-letter-routing-key String}\n :metadata                 Boolean (provide metadata to message hander function as 2nd arg.)\n :raw-payload              Boolean (provide message as raw payload (Byte array) instead of string)\n :failed-queue             String\n :failed-queue-auto-delete Boolean\n :failed-queue-durable     Boolean\n :failed-queue-exclusive   Boolean}\n```\n\n## Handling errors\n\nMessages are automatically acknowledged if the handler successfully processes the payload and automatically rejected if it fails. The consumer config accepts an `:on-error` key, which is a function that will be invoked when an error happens. The function should take the error and the received payload.\n\n```clojure\n(worker/consume connection\n                {:queue    \"pineapple-queue\"\n                 :on-error (fn [error payload] (log/error error))}\n                (fn [message] (println message)))\n```\n\n# Development\n\n### Running tests\nFor local testing with lein test, you need a RabbitMQ instance running locally.\n\n# License\n\nCopyright © 2017-2018 uSwitch.\n\nDistributed under the Eclipse Public License, the same as Clojure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuswitch%2Frabbitmq-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuswitch%2Frabbitmq-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuswitch%2Frabbitmq-worker/lists"}