{"id":22472596,"url":"https://github.com/jcarrano/ezamqp","last_synced_at":"2025-03-27T16:23:02.072Z","repository":{"id":69249483,"uuid":"73310723","full_name":"jcarrano/ezamqp","owner":"jcarrano","description":"Easy AMQP RPC management over asyncio","archived":false,"fork":false,"pushed_at":"2018-03-20T19:41:41.000Z","size":21,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T20:11:35.548Z","etag":null,"topics":["amqp","asyncio","python","rpc"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcarrano.png","metadata":{"files":{"readme":"README.rst","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-09T18:35:31.000Z","updated_at":"2018-03-14T15:39:50.000Z","dependencies_parsed_at":"2023-02-22T13:30:21.149Z","dependency_job_id":null,"html_url":"https://github.com/jcarrano/ezamqp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fezamqp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fezamqp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fezamqp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcarrano%2Fezamqp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcarrano","download_url":"https://codeload.github.com/jcarrano/ezamqp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245879584,"owners_count":20687405,"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","asyncio","python","rpc"],"created_at":"2024-12-06T12:16:30.867Z","updated_at":"2025-03-27T16:23:02.065Z","avatar_url":"https://github.com/jcarrano.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=========================================\nezamqp: asyncio and AMQP made even easier\n=========================================\n\n¿What is this?\n==============\n\nezamqp is a (very) thin layer over aioamqp. It allows you to\n\n- Easily connect object methods with queue callbacks, creating the\n  necessary queues.\n- Write callbacks like regular functions. ezamqp takes care of\n  serializing arguments, return data and exceptions.\n- Forget about ACKs.\n- Implement RPC, with a asyncio.Future based interface.\n- All of the above while retaining full control over the AMQP primitives.\n\nThis is not\n===========\n\n- A full featured anything. In fact it is intentionally stripped down as\n  much as useful.\n\nOverview\n========\n\nThe ``Queue`` class\n-------------------\n\nThis class encapsulates an AMQP channel and adds a default exchange.\nIt allows you to easily define queues and callbacks.\n\nYou must parse the message payload and properties, and ack the message\nif necessary.\n\nthe ``endpoint(...)`` decorator\n-------------------------------\n\nDecorate a class' methods with ``@endpoint`` to make them react to incoming\nmessage. Then call ``Queue.autoconnect(object)`` to create the queues and\nregister the object's methods as callbacks.\n\nThere are different endpoint types. The ``Queue`` class implements the\n``queue`` endpoint. ``RPC_`` implements ``rpc_`` and ``RPC`` implements\n``rpc``.\n\nThe ``RPC_`` class\n------------------\n\nThe ``RPC_`` class allows you to write your queue consumer callbacks in a\nmore human-friendly way, and automates the handling of acks and rejects.\n\nThe ``RPC`` class\n-----------------\n\nThe ``RPC`` class allows consumer callbacks to return a response to the\ninstance that sent the message.\n\nExample\n=======\n\nServer\n------\n\n.. code:: python\n\n  import asyncio\n  import sys\n  import logging\n  import datetime\n\n  logging.getLogger().setLevel(logging.DEBUG)\n\n  import aioamqp\n\n  from context import ezamqp as ezq\n\n  class Functions:\n      # you can use coroutines as handlers\n      @ezq.endpoint(\"rpc\")\n      async def format_kws(self, **kwargs):\n          return \"\\n\".join(\"{}={}\".format(*i) for i in kwargs.items())\n\n      # we can have one function listen to multiple routing_keys by using\n      # topics and the extended keyword\n      # you can use regular functions as handlers\n      @ezq.endpoint(\"rpc\", \"arithmetic.*\", extended = True)\n      def operations(self, proc_name, q_name, x, y):\n          if proc_name == 'arithmetic.add':\n              return x+y\n          elif proc_name == 'arithmetic.prod':\n              return x*y\n          else:\n              raise ValueError(\"operation not supported %s\", proc_name)\n\n      #you can do this to avoid duplicate code\n      rpc_ = ezq.endpoint(\"rpc_\")\n\n      @rpc_\n      def print_date(self):\n          print(datetime.datetime.utcnow())\n\n      # create a named queue\n      # This queue won't be deleted when the application exits.\n      @ezq.endpoint(\"rpc_\", \"spooler\", \"spooler\")\n      def print_date(self, job):\n          print(\"New job\", job)\n\n  async def setup(loop):\n      transport, protocol = await aioamqp.connect('172.17.0.2',\n                                  login='guest', password='guest')\n\n      channel = await protocol.channel()\n\n      rpcserver = ezq.RPC(loop, channel, 'amq.topic')\n\n      # If we are only using the server we don't need to start\n      # await rpcman.start()\n      print(\"Autoconnecting\")\n      await rpcserver.autoconnect(Functions())\n      print(\"Connected\")\n\n  logging.debug(\"Server Starting\")\n\n  loop = asyncio.get_event_loop()\n  loop.run_until_complete(setup(loop))\n  loop.run_forever()\n\nClient\n------\n\n.. code:: python\n\n  #!/usr/bin/env python3\n  # -*- coding: utf-8 -*-\n\n  import asyncio\n  import sys\n  import logging\n\n  logging.getLogger().setLevel(logging.DEBUG)\n\n  import aioamqp\n\n  from context import ezamqp as ezq\n\n  async def example():\n      transport, protocol = await aioamqp.connect('172.17.0.2',\n                                  login='guest', password='guest')\n\n      channel = await protocol.channel()\n\n      rpcman = ezq.RPC(loop, channel, 'amq.topic')\n      await rpcman.start_client()\n\n      adder_func = rpcman.rpc(\"arithmetic.add\")\n      proc_func = rpcman.rpc(\"arithmetic.prod\")\n      bad_func = rpcman.rpc(\"arithmetic.whatever\")\n\n      z = await (await adder_func(5, 6))\n      print(\"z=\",z)\n      y = await (await proc_func(z, 2.2))\n      print(\"y=\",y)\n\n      try:\n          w = await (await bad_func(8, 9))\n      except ezq.RemoteException as e:\n          print(\"Remote exception:\", e)\n          print(\"Remote traceback:\")\n          for l in e.remote_tb:\n              print(l)\n\n      await rpcman.rpc_(\"print_date\")()\n      await rpcman.rpc_(\"spooler\")(\"hello!\")\n\n      print(await (await rpcman.rpc(\"format_kws\")(a=7, b=\"hello\", c=[])))\n\n      transport.close()\n\n  logging.debug(\"Client Starting\")\n\n  loop = asyncio.get_event_loop()\n  loop.run_until_complete(example())\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcarrano%2Fezamqp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcarrano%2Fezamqp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcarrano%2Fezamqp/lists"}