# 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, heartbeat=30)
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) \
.with_heartbeat_interval(30)\
.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()
```
# Properties of builder from HijikiRabbit
## with_username
Set username of Rabbit Connection
## with_password
Set password of Rabbit Connection
## with_host
Set host of rabbit when use single node server
## with_port
SEt port of rabbit when use single node server
## with_cluster_hosts
Set a list of rabbit hosts:port when cluestered server.
Example: server-1:5672,server-1:5672,server-1:5672
## with_heartbeat_interval
Define heartbeat interval in seconds
## with_auto_ack
Define Auto_ack to publish message with autoack
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/76/8d/c5e3b6e046acdfeecba9ea0b3c20cb3ebc43f1048da7bd54305e44583b94/hijiki-1.0.64.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, heartbeat=30)\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 .with_heartbeat_interval(30)\\\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# Properties of builder from HijikiRabbit\n\n## with_username\nSet username of Rabbit Connection\n\n## with_password\nSet password of Rabbit Connection\n\n## with_host\nSet host of rabbit when use single node server\n\n## with_port\nSEt port of rabbit when use single node server\n\n## with_cluster_hosts\nSet a list of rabbit hosts:port when cluestered server.\nExample: server-1:5672,server-1:5672,server-1:5672\n\n## with_heartbeat_interval\nDefine heartbeat interval in seconds\n\n## with_auto_ack\nDefine Auto_ack to publish message with autoack\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Python Rabbit wrapper library to simplify to use Exchanges and Queues with decorators",
"version": "1.0.64",
"project_urls": null,
"split_keywords": [
"celery",
" kombu",
" rabbitmq",
" decorator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "908074388a005a0053b6a5365516d737ab01bb93aafbe494386a648a5bfc90d2",
"md5": "6f429e9cd9bb1c6de5232901a73dd1ae",
"sha256": "417b85ccdff2d4549b1e0bc4f8bea35d096c72a474483b2c108193bffc18d950"
},
"downloads": -1,
"filename": "hijiki-1.0.64-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f429e9cd9bb1c6de5232901a73dd1ae",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 19456,
"upload_time": "2024-11-29T11:41:02",
"upload_time_iso_8601": "2024-11-29T11:41:02.164194Z",
"url": "https://files.pythonhosted.org/packages/90/80/74388a005a0053b6a5365516d737ab01bb93aafbe494386a648a5bfc90d2/hijiki-1.0.64-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "768dc5e3b6e046acdfeecba9ea0b3c20cb3ebc43f1048da7bd54305e44583b94",
"md5": "3a5c7cab4366c1a73f2603a0f1584560",
"sha256": "8fc00454522aca322c405f1f41cd668c88df7dc1ecaf83accb78b828ed860229"
},
"downloads": -1,
"filename": "hijiki-1.0.64.tar.gz",
"has_sig": false,
"md5_digest": "3a5c7cab4366c1a73f2603a0f1584560",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 20040,
"upload_time": "2024-11-29T11:41:07",
"upload_time_iso_8601": "2024-11-29T11:41:07.681499Z",
"url": "https://files.pythonhosted.org/packages/76/8d/c5e3b6e046acdfeecba9ea0b3c20cb3ebc43f1048da7bd54305e44583b94/hijiki-1.0.64.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-29 11:41:07",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "hijiki"
}