{"id":15783621,"url":"https://github.com/deepmancer/rabbitmq-rpc","last_synced_at":"2025-04-01T14:32:08.691Z","repository":{"id":249295903,"uuid":"829179075","full_name":"deepmancer/rabbitmq-rpc","owner":"deepmancer","description":"RabbitMQ RPC is an async, ready-to-use Python framework for event-driven microservices.","archived":false,"fork":false,"pushed_at":"2024-08-16T11:43:47.000Z","size":64,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-11T20:02:08.795Z","etag":null,"topics":["event-driven","event-sourcing","eventbus","events","message-broker","message-bus","message-queue","microservice","microservices-architecture","python","rabbitmq","rabbitmq-client","rpc-client","rpc-framework"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepmancer.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":"2024-07-15T23:22:27.000Z","updated_at":"2024-08-27T13:00:19.000Z","dependencies_parsed_at":"2024-07-22T11:46:06.989Z","dependency_job_id":"053da8da-a7bc-4a20-94f2-8830552a4c13","html_url":"https://github.com/deepmancer/rabbitmq-rpc","commit_stats":null,"previous_names":["alirezaheidari-cs/rabbitmq_rpc","alirezaheidari-cs/rabbitmq-rpc","deepmancer/rabbitmq-rpc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Frabbitmq-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Frabbitmq-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Frabbitmq-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Frabbitmq-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepmancer","download_url":"https://codeload.github.com/deepmancer/rabbitmq-rpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246604612,"owners_count":20804100,"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":["event-driven","event-sourcing","eventbus","events","message-broker","message-bus","message-queue","microservice","microservices-architecture","python","rabbitmq","rabbitmq-client","rpc-client","rpc-framework"],"created_at":"2024-10-04T20:00:21.521Z","updated_at":"2025-04-01T14:32:08.678Z","avatar_url":"https://github.com/deepmancer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🐇📡 RabbitMQ RPC Client\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/RabbitMQ-FF6600.svg?style=for-the-badge\u0026logo=RabbitMQ\u0026logoColor=white\" alt=\"RabbitMQ\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/PyPI-3775A9.svg?style=for-the-badge\u0026logo=PyPI\u0026logoColor=white\" alt=\"PyPI\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/python-3670A0?style=for-the-badge\u0026logo=python\u0026logoColor=ffdd54\" alt=\"Python\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=for-the-badge\" alt=\"License\"\u003e\n\u003c/p\u003e\n\n`rabbitmq_rpc` is a powerful Python package that simplifies the implementation of RPC (Remote Procedure Call) patterns in event-driven microservices. Built on top of the `aio-pika` library, it abstracts the complexities of asynchronous communication with RabbitMQ, providing a seamless and efficient experience for developers.\n\n---\n\n\n| **Source Code** | **Website** |\n|:-----------------|:------------|\n| \u003ca href=\"https://github.com/deepmancer/rabbitmq-rpc\" target=\"_blank\"\u003egithub.com/deepmancer/rabbitmq-rpc\u003c/a\u003e | \u003ca href=\"https://deepmancer.github.io/rabbitmq-rpc/\" target=\"_blank\"\u003edeepmancer.github.io/rabbitmq-rpc\u003c/a\u003e |\n\n---\n\n\n## ✨ Features\n\n- **🚀 Asynchronous RPC Client:** Fully built on `aio-pika`, enabling non-blocking inter-service communication.\n- **🌐 Distributed Environment Ready:** Effortlessly connects services across containers and different URLs.\n- **📜 Event Registration \u0026 Handling:** Easily define, register, and handle events with custom event handlers.\n- **🛠️ Customizable RPC Protocol:** Supports any subclass of `aio_pika.patterns.RPC` for tailored RPC interactions.\n- **🔒 Thread-Safe Connection:** Utilizes a singleton design pattern to maintain a single instance of the RPC client across threads.\n- **⏱️ Retry \u0026 Timeout Mechanism:** Built-in support for retrying failed calls and handling timeouts with `with_retry_and_timeout`.\n- **🛠️ No Server-side Implementation Required:** Just a running RabbitMQ server—no need for additional RPC server implementations.\n\n## 📦 Installation\n\nGet started by installing `rabbitmq_rpc` using pip:\n\n```sh\npip install git+https://github.com/deepmancer/rabbitmq-rpc.git\n```\n\n## 🛠️ Quick Start\n\n### 🎯 Registering Events\n\nIn `Service 1`, define event handlers and register them with the `RPCClient` using the `register_event` method:\n\n```python\nimport asyncio\nfrom rabbitmq_rpc import RPCClient\n\nasync def handler_addition(x, y):\n    return x + y\n\nasync def handle_subtraction(x, y):\n    return x - y\n\nasync def handle_multiplication(x, y):\n    return x * y\n\nasync def handle_division(x, y):\n    return x / y\n\nasync def main():\n    # Initialize RPC client\n    rpc_client = await RPCClient.create(\n        host='localhost',\n        port=5920,\n        user='rabbitmq_user',\n        password='rabbitmq_password',\n        vhost='/',\n        ssl=False,\n    )\n\n    # Register event handlers\n    await rpc_client.register_event('service1.addition', handler_addition)\n    await rpc_client.register_event('service1.subtraction', handle_subtraction)\n    await rpc_client.register_event('service1.multiplication', handle_multiplication)\n    await rpc_client.register_event('service1.division', handle_division)\n    \n    # Keep listening for events\n    await asyncio.Future()\n\nif __name__ == '__main__':\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(main())\n```\n\n### 📞 Calling Events\n\nIn `Service 2`, invoke the events defined in `Service 1`:\n\n```python\nimport asyncio\nfrom rabbitmq_rpc import RPCClient\n\nasync def main():\n    # Initialize RPC client\n    rpc_client = await RPCClient.create(\n        host='localhost',\n        port=5920,\n        user='rabbitmq_user',\n        password='rabbitmq_password',\n        vhost='/',\n        ssl=False,\n    )\n    \n    # Call service1 events\n    add_result = await rpc_client.call('service1.addition', data={\"x\": 1, \"y\": 2})\n    print(f\"Addition Result: {add_result}\")\n\n    sub_result = await rpc_client.call('service1.subtraction', data={\"x\": 1, \"y\": 2})\n    print(f\"Subtraction Result: {sub_result}\")\n\n    mul_result = await rpc_client.call('service1.multiplication', data={\"x\": 1, \"y\": 2})\n    print(f\"Multiplication Result: {mul_result}\")\n\n    # Call with timeout and retry mechanism\n    div_result = await rpc_client.call('service1.division', data={\"x\": 5, \"y\": 2}, timeout=10, retry_count=3)\n    print(f\"Division Result: {div_result}\")\n\n    # Send event without waiting for a response\n    rpc_client.send('service1.multiplication', data={\"x\": 1, \"y\": 2})    \n\nif __name__ == '__main__':\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(main())\n```\n\n### 🛡️ Error Handling\n\n`rabbitmq_rpc` provides custom exceptions to handle various connection and RPC-related issues:\n\n- `ConnectionError`\n- `RPCError`\n- `EventRegistrationError`\n- `EventPublishError`\n- `EventSubscribeError`\n\n### 🔌 Disconnecting\n\nGracefully disconnect from RabbitMQ when you're done:\n\n```python\nawait rpc_client.close()\n```\n\n## 📄 License\n\nThis project is licensed under the Apache License 2.0. For more details, see the [LICENSE](https://github.com/deepmancer/rabbitmq-rpc/blob/main/LICENSE) file.\n\n---\n\n**Elevate your microservices communication with `rabbitmq_rpc` today!** 🐇📡\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepmancer%2Frabbitmq-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepmancer%2Frabbitmq-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepmancer%2Frabbitmq-rpc/lists"}