# Hijiki
Python Rabbit wrapper library to simplify to use Exchanges and Queues with decorators
## Configurations
Hijiki uses environment variables to configure connection with BROKER.
### COMMON
- BROKER_PWD
- BROKER_USERNAME
### For single server
- BROKER_PORT
- BROKER_SERVER
### For cluster server
- BROKER_CLUSTER_SERVER
if BROKER_CLUSTER_SERVER is present the priority is generate URI using this list of servers, and not use the sever for single server.
To user multiples server from cluster is necessary this environment variable has a list of server with port separates with comma.
Ex:
```
serverA:5672,serverB:5673
```
generating for uri connection string the value above
``
amqp://usr:password@server:5672;amqp://usr:password@serverB:5672;
``
The user and password is the same for all servers.
If server is not present, even BROKER_CLUSTER_SERVER, the connection url will be a default, and to others configs will be changed for "teste".
## How to use
### Publisher
The example demonstrate how to publish a simple message to topic "teste1_event" with a json message:
```python
pub = Publisher("localhost", "rabbitmq", "rabbitmq", 5672)
pub.publish_message('teste1_event', '{"value": "Esta é a mensagem"}')
```
### Consumer
Consumer uses a configuration to define QUEUES and Exchanges and the consumer is a decorator for the queue.
```python
from hijiki.broker.hijiki_rabbit import HijikiQueueExchange, HijikiRabbit
qs = [HijikiQueueExchange('teste1', 'teste1_event'), HijikiQueueExchange('teste2', 'teste2_event')]
gr = HijikiRabbit().with_queues_exchange(qs) \
.with_username("rabbitmq") \
.with_password("rabbitmq") \
.with_host("localhost") \
.with_port(5672) \
.build()
class MyConsumer():
@gr.task(queue_name='teste1')
def my_consumer(data):
print(f"consumer 1 executed with data : {data}")
@gr.task(queue_name='teste2')
def my_consumer2(data):
print(f"consumer 2 executed with data : {data}")
if __name__ == '__main__':
MyConsumer()
gr.run()
```
Raw data
{
"_id": null,
"home_page": null,
"name": "hijiki",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "Celery, Kombu, RabbitMQ, decorator",
"author": "Leandro Vilson Battisti",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/82/f1/585ef74b897d4d78bef06905fa3bfbf89bdaa1267ada81d66bd6f3b0979f/hijiki-1.0.58.tar.gz",
"platform": null,
"description": "# Hijiki\nPython Rabbit wrapper library to simplify to use Exchanges and Queues with decorators\n\n## Configurations\nHijiki uses environment variables to configure connection with BROKER. \n\n### COMMON\n- BROKER_PWD\n- BROKER_USERNAME\n\n### For single server\n- BROKER_PORT\n- BROKER_SERVER\n\n### For cluster server\n- BROKER_CLUSTER_SERVER\n\nif BROKER_CLUSTER_SERVER is present the priority is generate URI using this list of servers, and not use the sever for single server. \nTo user multiples server from cluster is necessary this environment variable has a list of server with port separates with comma. \n\nEx: \n```\nserverA:5672,serverB:5673\n\n```\ngenerating for uri connection string the value above\n\n``\namqp://usr:password@server:5672;amqp://usr:password@serverB:5672;\n``\n\nThe user and password is the same for all servers.\n\n\nIf server is not present, even BROKER_CLUSTER_SERVER, the connection url will be a default, and to others configs will be changed for \"teste\".\n\n## How to use\n### Publisher\nThe example demonstrate how to publish a simple message to topic \"teste1_event\" with a json message:\n\n```python\npub = Publisher(\"localhost\", \"rabbitmq\", \"rabbitmq\", 5672)\npub.publish_message('teste1_event', '{\"value\": \"Esta \u00e9 a mensagem\"}')\n```\n\n### Consumer\nConsumer uses a configuration to define QUEUES and Exchanges and the consumer is a decorator for the queue.\n\n```python\nfrom hijiki.broker.hijiki_rabbit import HijikiQueueExchange, HijikiRabbit\n\nqs = [HijikiQueueExchange('teste1', 'teste1_event'), HijikiQueueExchange('teste2', 'teste2_event')]\ngr = HijikiRabbit().with_queues_exchange(qs) \\\n .with_username(\"rabbitmq\") \\\n .with_password(\"rabbitmq\") \\\n .with_host(\"localhost\") \\\n .with_port(5672) \\\n .build()\n\nclass MyConsumer():\n @gr.task(queue_name='teste1')\n def my_consumer(data):\n print(f\"consumer 1 executed with data : {data}\")\n\n @gr.task(queue_name='teste2')\n def my_consumer2(data):\n print(f\"consumer 2 executed with data : {data}\")\n\nif __name__ == '__main__':\n MyConsumer()\n gr.run()\n```\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Python Rabbit wrapper library to simplify to use Exchanges and Queues with decorators",
"version": "1.0.58",
"project_urls": null,
"split_keywords": [
"celery",
" kombu",
" rabbitmq",
" decorator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ffc4e8f725f2c769d45388ef9cb2e084d1d9e2aa6d04672b5c40ad8dbf581331",
"md5": "4530471a80664fa396e77d04ded49a20",
"sha256": "abf402a3c5ccff37cc1b4fdfad2a5412876a50008815199f8efc713bf9a4cce7"
},
"downloads": -1,
"filename": "hijiki-1.0.58-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4530471a80664fa396e77d04ded49a20",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 19047,
"upload_time": "2024-04-08T20:48:08",
"upload_time_iso_8601": "2024-04-08T20:48:08.100789Z",
"url": "https://files.pythonhosted.org/packages/ff/c4/e8f725f2c769d45388ef9cb2e084d1d9e2aa6d04672b5c40ad8dbf581331/hijiki-1.0.58-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82f1585ef74b897d4d78bef06905fa3bfbf89bdaa1267ada81d66bd6f3b0979f",
"md5": "85c3c4d923e6c07e527ef6e2688d2c1a",
"sha256": "023f76a6cf88816109f89fbffc6fbe4bb3fccf3c2e86a4377738b9fdc903c025"
},
"downloads": -1,
"filename": "hijiki-1.0.58.tar.gz",
"has_sig": false,
"md5_digest": "85c3c4d923e6c07e527ef6e2688d2c1a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 19405,
"upload_time": "2024-04-08T20:48:09",
"upload_time_iso_8601": "2024-04-08T20:48:09.401099Z",
"url": "https://files.pythonhosted.org/packages/82/f1/585ef74b897d4d78bef06905fa3bfbf89bdaa1267ada81d66bd6f3b0979f/hijiki-1.0.58.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-08 20:48:09",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "hijiki"
}