{ "info": { "author": "System73 Engineering Team", "author_email": "opensource@system73.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3.6" ], "description": "# tamarco-amqp\n\n[![Build Status](https://travis-ci.com/System73/tamarco-amqp.svg?branch=master)](https://travis-ci.com/System73/tamarco-amqp)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=System73_tamarco-amqp&metric=coverage)](https://sonarcloud.io/dashboard?id=System73_tamarco-amqp)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=System73_tamarco-amqp&metric=alert_status)](https://sonarcloud.io/dashboard?id=System73_tamarco-amqp)\n\nAMQP resource for Tamarco microservice framework.\n\n## Settings\n\nThis resource depends on the following configuration schema:\n\n```yaml\n system:\n resources:\n amqp:\n host: 127.0.0.1\n port: 5672\n vhost: /\n user: microservice\n password: 1234\n connection_timeout: 10\n queues_prefix: \"prefix\"\n```\n\n## Inputs and outputs\n\nThe inputs and outputs need to be declared in the resource.\n\nThree different communication patterns can be used.\n\nA specific input is required for each message pattern, but the same output is valid for all message patterns. Each message pattern has a different method in the output.\n\nWith the JsonCodec the input and the output are directly Python dictionaries.\n\n### Publish-subscribe pattern\n\nIn the pub-sub pattern a message reaches all the services subscribed to the queue. It can be used to notify events to anyone who needs it.\n\n#### Input\n\nThe `AMQPSubscriptionInput` can be used as a decorator.\n\n```python\nclass AmqpMicroservice():\n amqp = AMQPResource()\n\n @AMQPSubscriptionInput(resource=amqp, queue='cows', codec=JsonCodec)\n async def consume_messages(self, message):\n self.logger.info(f'Consumed message from cows subscription queue: {message}')\n```\n\nOr as a async iterator:\n\n```python\nclass AmqpMicroservice():\n cows_input = AMQPSubscriptionInput(queue='cows', codec=JsonCodec)\n amqp = AMQPResource(inputs=[cows_input])\n\n @task\n async def consume_cows(self):\n async for message in self.cows_input:\n self.logger.info(f'Consumed message from cows subscription queue: {message}')\n```\n\n#### Output\n\nUse the `publish` method of the output.\n\n```python\nclass AmqpMicroservice():\n cows_output = AMQPOutput(queue='cows', codec=JsonCodec)\n amqp = AMQPResource(outputs=[cows_output])\n\n @task_timer(interval=1000, autostart=True)\n async def metric_producer(self):\n await cows_output.publish({'my_json_message': 'to_cow_queue'})\n```\n\n### Push-pull pattern\n\nThe push-pull pattern is a work queue where each message is only pulled by one of the services subscribed to the queue. Commonly used to distribute the work in a pull of instances.\n\n#### Input\n\n`AMQPPullInput` is used to declare a input pull queue, and example used as decorator: \n\n```python\nclass AmqpMicroservice():\n amqp = AMQPResource()\n\n @AMQPPullInput(resource=amqp, queue='cows', codec=JsonCodec)\n async def consume_messages(self, message):\n self.logger.info(f'Consumed message from cows pull queue: {message}')\n```\n\nIt can be used as an async iterator in the same way that the pub/sub pattern.\n\n#### Output \n\nUse the `push` method of the `AMQPOutput`. In the following\n\n```python\nclass AmqpMicroservice():\n cows_output = AMQPOutput(queue='cows', codec=JsonCodec)\n amqp = AMQPResource(outputs=[cows_output])\n\n @task_timer(interval=1000, autostart=True)\n async def metric_producer(self):\n await cows_output.push({'my_json_message': 'to_cow_queue'})\n```\n\n### Request-response pattern\n\nIn the request-response pattern each request is handled by one of the instances subscribed to the queue and unlike the other patterns, each request has an answer. \n\n#### Input \n\n`AMQPRequestInput` is used to declare a input request response queue. An example used as decorator:\n\n```python\nclass AmqpMicroservice():\n amqp = AMQPResource()\n\n @AMQPRequestInput(resource=amqp, queue='cows', codec=JsonCodec)\n async def consume_messages(self, message, response_handler):\n self.logger.info(f'Consumed message from cows queue: {message}')\n await response_handler.send_response({'cows': 'response'})\n```\n\nIn this case the handler takes two input objects, and one of them send the response.\n\n#### Output\n\nThe output is like the rest of them but it returns a response.\n\n```python\nclass AmqpMicroservice():\n cows_output = AMQPOutput(queue='cows', codec=JsonCodec)\n amqp = AMQPResource()\n\n @task_timer(interval=1000, autostart=True)\n async def request_response(self):\n message = {'cow': 'MOOOO'}\n response = await cows_output.request(message)\n self.logger.info(f'Response from cows queue: {response}')\n```\n\n## How to run the examples\n\nTo run them you just need to launch the docker-compose, install the requirements and run it.\n\n```python3\npip install -r examples/requirements.txt\ndocker-compose up -d\npython examples/microservice_stream_input.py\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/System73/tamarco-amqp", "keywords": "tamarco,amqp,microservices", "license": "", "maintainer": "", "maintainer_email": "", "name": "tamarco-amqp", "package_url": "https://pypi.org/project/tamarco-amqp/", "platform": "", "project_url": "https://pypi.org/project/tamarco-amqp/", "project_urls": { "Homepage": "https://github.com/System73/tamarco-amqp" }, "release_url": "https://pypi.org/project/tamarco-amqp/0.1.0/", "requires_dist": null, "requires_python": "", "summary": "AMQP resource for Tamarco microservice framework.", "version": "0.1.0" }, "last_serial": 5890424, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "1c06847c2f4f7b4f036fd57d79fc452e", "sha256": "c81ae3ec0f453bd3394a1c28f79b224ea26795abe1cbf92d79370ea10448c49e" }, "downloads": -1, "filename": "tamarco-amqp-0.1.0.tar.gz", "has_sig": false, "md5_digest": "1c06847c2f4f7b4f036fd57d79fc452e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14558, "upload_time": "2019-09-26T12:40:36", "url": "https://files.pythonhosted.org/packages/10/c4/488edb812d1934bfdae44761cb71b9635ad245c42a9f7778392c86320eb7/tamarco-amqp-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1c06847c2f4f7b4f036fd57d79fc452e", "sha256": "c81ae3ec0f453bd3394a1c28f79b224ea26795abe1cbf92d79370ea10448c49e" }, "downloads": -1, "filename": "tamarco-amqp-0.1.0.tar.gz", "has_sig": false, "md5_digest": "1c06847c2f4f7b4f036fd57d79fc452e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14558, "upload_time": "2019-09-26T12:40:36", "url": "https://files.pythonhosted.org/packages/10/c4/488edb812d1934bfdae44761cb71b9635ad245c42a9f7778392c86320eb7/tamarco-amqp-0.1.0.tar.gz" } ] }