{"id":22468497,"url":"https://github.com/projectweekend/pika-pack","last_synced_at":"2025-03-27T15:44:33.629Z","repository":{"id":27364045,"uuid":"30839487","full_name":"projectweekend/Pika-Pack","owner":"projectweekend","description":"Handy components when working with RabbitMQ and Pika (https://pika.readthedocs.org/en/latest/)","archived":false,"fork":false,"pushed_at":"2015-05-02T23:27:20.000Z","size":224,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T14:07:36.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/projectweekend.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","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":"2015-02-15T19:44:34.000Z","updated_at":"2017-07-08T06:58:36.000Z","dependencies_parsed_at":"2022-08-28T16:40:57.631Z","dependency_job_id":null,"html_url":"https://github.com/projectweekend/Pika-Pack","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/projectweekend%2FPika-Pack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FPika-Pack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FPika-Pack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FPika-Pack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectweekend","download_url":"https://codeload.github.com/projectweekend/Pika-Pack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245874183,"owners_count":20686719,"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-06T11:16:59.638Z","updated_at":"2025-03-27T15:44:33.599Z","avatar_url":"https://github.com/projectweekend.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a small collection of things that I've found useful working with [RabbitMQ](http://www.rabbitmq.com/) using the [Pika](https://pika.readthedocs.org/en/latest/) library.\n\n\n### RPCBlockingConsumer\n\nThis class connects to RabbitMQ, binds an `exchange` and `routing_key`, and listens for new messages. The `request_action` parameter is a function that itself receives a single parameter of the incoming message body as a dictionary. This function is used to perform any custom operations, and should return another dictionary. The resulting dictionary becomes the message body that is sent back to the sender via the `reply_to` queue. The `reconnect_attempts` parameter is the number of times you would like the listener to attempt reconnection to RabbitMQ should the connection be lost after it starts to consume messages.\n\nOnce an instance of `RPCBlockingConsumer` is created, call the `start` method to begin processing messages. This is a blocking operation.\n\n**Example:**\n```python\nRABBIT_URL = 'rabbit server connection URL'\nEXCHANGE = 'name_of_exchange'\nROUTING_KEY = 'name_of_routing_key'\nRECONNECT_ATTEMPTS = 3\n\n\ndef my_custom_action(message):\n    # do something with message dictionary\n    # return another dictionary as response\n    return {'body': 'Message received!'}\n\n\nrpc_consumer = RPCBlockingConsumer(\n    rabbit_url=RABBIT_URL,\n    exchange=EXCHANGE,\n    routing_key=ROUTING_KEY,\n    request_action=my_custom_action,\n    reconnect_attempts=RECONNECT_ATTEMPTS)\n\nrpc_consumer.start()\n```\n\n\n### RPCBlockingClient\n\nThis class connects to RabbitMQ, binds an 'exchange', then allows you to send a `message` to a `routing_key` using the `call` method. This method will block until it receives a response message from the RPC queue. The `call` method returns a dictionary representing the received message.\n\n**Example:**\n```python\nRABBIT_URL = 'rabbit server connection URL'\nEXCHANGE = 'name_of_exchange'\n\n\nrpc_client = RPCBlockingClient(rabbit_url=RABBIT_URL, exchange=EXCHANGE)\n\nmessage = {\n    'body': 'Some message body'\n}\n# response will be a dictionary of the response message from RPCBlockingConsumer\nresponse = rpc_client.call(routing_key='name_of_routing_key', message=message)\n```\n\n### Sender\n\nThis class sends messages to a 'direct' exchange, where only one consumer will receive the message.\n\n**Example:**\n```python\nfrom pika_pack import Sender\n\n\nRABBIT_URL = 'rabbit server connection URL'\nEXCHANGE = 'name_of_exchange'\n\n\nsender = Sender(rabbit_url=RABBIT_URL, exchange=EXCHANGE)\n\nmessage = {\n    'body': 'Some message body'\n}\n\nsender.send('some_routing_key', message)\n```\n\n\n### Broadcaster\n\nThis class sends messages to a 'fanout' exchange, where all consumers will receive the message.\n\n**Example:**\n```python\nfrom pika_pack import Broadcaster\n\n\nRABBIT_URL = 'rabbit server connection URL'\nEXCHANGE = 'name_of_exchange'\n\n\nbroadcaster = Broadcaster(rabbit_url=RABBIT_URL, exchange=EXCHANGE)\n\nmessage = {\n    'body': 'Some message body'\n}\n\nbroadcaster.send('some_routing_key', message)\n```\n\n\n### Receiver\n\nThis class receives messages from a 'direct' exchange, where only one consumer will receive the message.\n\n**Example:**\n```python\nfrom pika_pack import Receiver\n\n\nRABBIT_URL = 'rabbit server connection URL'\nEXCHANGE = 'name_of_exchange'\nROUTING_KEY = 'some_routing_key'\nRECONNECT_ATTEMPTS = 3\n\n\ndef my_custom_action(message):\n    # do something with message dictionary this\n    # function doesn't need to return anything\n    pass\n\n\nreceiver = Receiver(\n    rabbit_url=RABBIT_URL,\n    exchange=EXCHANGE,\n    routing_key=ROUTING_KEY,\n    request_action=my_custom_action,\n    reconnect_attempts=RECONNECT_ATTEMPTS)\n\nreceiver.start()\n```\n\n\n### Listener\n\nThis class receives messages from a 'fanout' exchange, where all consumers will receive the message.\n\n**Example:**\n```python\nfrom pika_pack import Listener\n\n\nRABBIT_URL = 'rabbit server connection URL'\nEXCHANGE = 'name_of_exchange'\nROUTING_KEY = 'some_routing_key'\nRECONNECT_ATTEMPTS = 3\n\n\ndef my_custom_action(message):\n    # do something with message dictionary this\n    # function doesn't need to return anything\n    pass\n\n\nlistener = Listener(\n    rabbit_url=RABBIT_URL,\n    exchange=EXCHANGE,\n    routing_key=ROUTING_KEY,\n    request_action=my_custom_action,\n    reconnect_attempts=RECONNECT_ATTEMPTS)\n\nlistener.start()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fpika-pack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectweekend%2Fpika-pack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fpika-pack/lists"}