gh-rabbit-hole


Namegh-rabbit-hole JSON
Version 1.6.0 PyPI version JSON
download
home_pagehttps://github.com/m-ghiani/RABBIT_HOLE
SummaryPackage for communication with RabbitMQ
upload_time2024-01-01 05:34:29
maintainer
docs_urlNone
authorMassimo Ghiani
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Asyncio Rabbit Manager
======================

An advanced Python package to asynchronously manage RabbitMQ
connections, queues, and message handling using asyncio. Ideal for
high-performance, non-blocking applications.

Features
--------

-  **Asynchronous Operations**: Utilize the full potential of asyncio
   for non-blocking message sending and receiving.
-  **Customizable Logging**: Leverage colored logs for better monitoring
   and debugging.
-  **Connection Resilience**: Automatically reconnects in case of
   connection failures.
-  **Message Handling**: Send and receive messages asynchronously with
   optional callbacks.
-  **Factory Design**: Utilize the factory pattern for creating
   instances with various configurations.

Installation
------------

Install the package via pip:

.. code:: bash

   pip install asyncio-rabbit-manager

Usage
-----

Basic Setup
~~~~~~~~~~~

First, import the necessary classes:

.. code:: python

   from asyncio_rabbit_manager import AsyncioRabbitManagerFactory, AsyncioRabbitManager

Creating a Manager
~~~~~~~~~~~~~~~~~~

Use the factory to create an instance of ``AsyncioRabbitManager``:

.. code:: python

   factory = AsyncioRabbitManagerFactory()
   rabbit_manager = factory.create('<config_file_name>')

Sending Messages
~~~~~~~~~~~~~~~~

Send messages to a specified queue:

.. code:: python

   rabbit_manager.send_message('Hello, World!', 'my_queue')

Receiving Messages
~~~~~~~~~~~~~~~~~~

Define a callback for incoming messages and start listening:

.. code:: python

   async def handle_message(channel, method, properties, body):
       print("Received message:", body)

   rabbit_manager.on_message_callback = handle_message
   await rabbit_manager.connect()

Closing Connection
~~~~~~~~~~~~~~~~~~

Properly close the connection when done:

.. code:: python

   await rabbit_manager.close_connection()

Advanced Usage
--------------

The ``AsyncioRabbitManager`` class provides an asynchronous interface
for connecting and interacting with RabbitMQ using Python and asyncio.
Designed for applications requiring reactive and non-blocking
processing, this class manages the connection to RabbitMQ, sending and
receiving messages, and declaring exchanges and queues, all
asynchronously.

.. _features-1:

Features
~~~~~~~~

-  **Asynchronous Connection:** Establishes non-blocking connections to
   RabbitMQ, allowing the rest of the application to continue executing
   while managing network operations in the background.
-  **Channel Management:** Opens and configures RabbitMQ channels to
   send and receive messages.
-  **Message Sending and Receiving:** Supports sending messages to
   queues or exchanges and configuring asynchronous callbacks for
   incoming message handling.
-  **Asyncio Integration:** Built around asyncio primitives for easy
   integration with other asynchronous operations and the event loop.
-  **Advanced Logging:** Utilizes a customizable logging system to
   monitor activities and quickly diagnose issues.

.. _usage-1:

Usage
~~~~~

Ideal for asyncio-based applications that require efficient and
asynchronous communication with RabbitMQ. Especially useful in contexts
where performance and responsiveness are critical, such as in
microservices, bots, or real-time data processing systems.

Initialization
^^^^^^^^^^^^^^

.. code:: python

   import logging
   from your_module import AsyncioRabbitManager  # Replace with the actual module name

   logger = logging.getLogger(__name__)

   rabbit_manager = AsyncioRabbitManager(
       amqp_url="your_amqp_url",
       sending_queue="your_sending_queue",
       listening_queue="your_listening_queue",
       sending_exchange="your_sending_exchange",
       logger=logger,
       on_message_callback=your_message_callback_function  # Replace with your callback
   )

Connecting to RabbitMQ
^^^^^^^^^^^^^^^^^^^^^^

.. code:: python

   import asyncio

   async def main():
       await rabbit_manager.connect()

   asyncio.run(main())

.. _sending-messages-1:

Sending Messages
^^^^^^^^^^^^^^^^

.. code:: python

   message = {"key": "value"}  # Your message content
   routing_key = "your_routing_key"  # Optional
   to_exchange = False  # Set to True if sending to an exchange

   rabbit_manager.send_message(message, routing_key, to_exchange)

.. _receiving-messages-1:

Receiving Messages
^^^^^^^^^^^^^^^^^^

Implement your message handling logic in a callback function:

.. code:: python

   async def message_handler(channel, method, properties, body):
       print("Received message:", body)

   # Set this as your callback
   rabbit_manager.on_message_callback = message_handler

Closing the Connection
^^^^^^^^^^^^^^^^^^^^^^

.. code:: python

   async def close():
       await rabbit_manager.close_connection()

   asyncio.run(close())

Contributing
------------

Contributions, issues, and feature requests are welcome!

License
-------

Distributed under the MIT License. See ``LICENSE`` for more information.

Contact
-------

Massimo Ghiani - m.ghiani@gmail.com

Project Link: https://github.com/m-ghiani/RABBIT_HOLE

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/m-ghiani/RABBIT_HOLE",
    "name": "gh-rabbit-hole",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "",
    "author": "Massimo Ghiani",
    "author_email": "m.ghiani@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/02/bb/a40d61a4453fff94bf41a4dd90d54bfd38ef4d033d3ea241c6064891f3a8/gh-rabbit-hole-1.6.0.tar.gz",
    "platform": null,
    "description": "Asyncio Rabbit Manager\n======================\n\nAn advanced Python package to asynchronously manage RabbitMQ\nconnections, queues, and message handling using asyncio. Ideal for\nhigh-performance, non-blocking applications.\n\nFeatures\n--------\n\n-  **Asynchronous Operations**: Utilize the full potential of asyncio\n   for non-blocking message sending and receiving.\n-  **Customizable Logging**: Leverage colored logs for better monitoring\n   and debugging.\n-  **Connection Resilience**: Automatically reconnects in case of\n   connection failures.\n-  **Message Handling**: Send and receive messages asynchronously with\n   optional callbacks.\n-  **Factory Design**: Utilize the factory pattern for creating\n   instances with various configurations.\n\nInstallation\n------------\n\nInstall the package via pip:\n\n.. code:: bash\n\n   pip install asyncio-rabbit-manager\n\nUsage\n-----\n\nBasic Setup\n~~~~~~~~~~~\n\nFirst, import the necessary classes:\n\n.. code:: python\n\n   from asyncio_rabbit_manager import AsyncioRabbitManagerFactory, AsyncioRabbitManager\n\nCreating a Manager\n~~~~~~~~~~~~~~~~~~\n\nUse the factory to create an instance of ``AsyncioRabbitManager``:\n\n.. code:: python\n\n   factory = AsyncioRabbitManagerFactory()\n   rabbit_manager = factory.create('<config_file_name>')\n\nSending Messages\n~~~~~~~~~~~~~~~~\n\nSend messages to a specified queue:\n\n.. code:: python\n\n   rabbit_manager.send_message('Hello, World!', 'my_queue')\n\nReceiving Messages\n~~~~~~~~~~~~~~~~~~\n\nDefine a callback for incoming messages and start listening:\n\n.. code:: python\n\n   async def handle_message(channel, method, properties, body):\n       print(\"Received message:\", body)\n\n   rabbit_manager.on_message_callback = handle_message\n   await rabbit_manager.connect()\n\nClosing Connection\n~~~~~~~~~~~~~~~~~~\n\nProperly close the connection when done:\n\n.. code:: python\n\n   await rabbit_manager.close_connection()\n\nAdvanced Usage\n--------------\n\nThe ``AsyncioRabbitManager`` class provides an asynchronous interface\nfor connecting and interacting with RabbitMQ using Python and asyncio.\nDesigned for applications requiring reactive and non-blocking\nprocessing, this class manages the connection to RabbitMQ, sending and\nreceiving messages, and declaring exchanges and queues, all\nasynchronously.\n\n.. _features-1:\n\nFeatures\n~~~~~~~~\n\n-  **Asynchronous Connection:** Establishes non-blocking connections to\n   RabbitMQ, allowing the rest of the application to continue executing\n   while managing network operations in the background.\n-  **Channel Management:** Opens and configures RabbitMQ channels to\n   send and receive messages.\n-  **Message Sending and Receiving:** Supports sending messages to\n   queues or exchanges and configuring asynchronous callbacks for\n   incoming message handling.\n-  **Asyncio Integration:** Built around asyncio primitives for easy\n   integration with other asynchronous operations and the event loop.\n-  **Advanced Logging:** Utilizes a customizable logging system to\n   monitor activities and quickly diagnose issues.\n\n.. _usage-1:\n\nUsage\n~~~~~\n\nIdeal for asyncio-based applications that require efficient and\nasynchronous communication with RabbitMQ. Especially useful in contexts\nwhere performance and responsiveness are critical, such as in\nmicroservices, bots, or real-time data processing systems.\n\nInitialization\n^^^^^^^^^^^^^^\n\n.. code:: python\n\n   import logging\n   from your_module import AsyncioRabbitManager  # Replace with the actual module name\n\n   logger = logging.getLogger(__name__)\n\n   rabbit_manager = AsyncioRabbitManager(\n       amqp_url=\"your_amqp_url\",\n       sending_queue=\"your_sending_queue\",\n       listening_queue=\"your_listening_queue\",\n       sending_exchange=\"your_sending_exchange\",\n       logger=logger,\n       on_message_callback=your_message_callback_function  # Replace with your callback\n   )\n\nConnecting to RabbitMQ\n^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n   import asyncio\n\n   async def main():\n       await rabbit_manager.connect()\n\n   asyncio.run(main())\n\n.. _sending-messages-1:\n\nSending Messages\n^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n   message = {\"key\": \"value\"}  # Your message content\n   routing_key = \"your_routing_key\"  # Optional\n   to_exchange = False  # Set to True if sending to an exchange\n\n   rabbit_manager.send_message(message, routing_key, to_exchange)\n\n.. _receiving-messages-1:\n\nReceiving Messages\n^^^^^^^^^^^^^^^^^^\n\nImplement your message handling logic in a callback function:\n\n.. code:: python\n\n   async def message_handler(channel, method, properties, body):\n       print(\"Received message:\", body)\n\n   # Set this as your callback\n   rabbit_manager.on_message_callback = message_handler\n\nClosing the Connection\n^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n   async def close():\n       await rabbit_manager.close_connection()\n\n   asyncio.run(close())\n\nContributing\n------------\n\nContributions, issues, and feature requests are welcome!\n\nLicense\n-------\n\nDistributed under the MIT License. See ``LICENSE`` for more information.\n\nContact\n-------\n\nMassimo Ghiani - m.ghiani@gmail.com\n\nProject Link: https://github.com/m-ghiani/RABBIT_HOLE\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Package for communication with RabbitMQ",
    "version": "1.6.0",
    "project_urls": {
        "Documentation": "https://github.com/m-ghiani/RABBIT_HOLE/tree/main/rabbit_manager_package/documentation",
        "Homepage": "https://github.com/m-ghiani/RABBIT_HOLE"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54f113e86962a9a8e2abe514b6f1a7b07f865e487450ddd67dffacf3a4a6973d",
                "md5": "61a8a1919a59fada6728961d3020af35",
                "sha256": "cb103b438d3f61042fc8458d5c7a17be1351a8656135951bcd0303e95f97c4b0"
            },
            "downloads": -1,
            "filename": "gh_rabbit_hole-1.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "61a8a1919a59fada6728961d3020af35",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 19735,
            "upload_time": "2024-01-01T05:34:28",
            "upload_time_iso_8601": "2024-01-01T05:34:28.100259Z",
            "url": "https://files.pythonhosted.org/packages/54/f1/13e86962a9a8e2abe514b6f1a7b07f865e487450ddd67dffacf3a4a6973d/gh_rabbit_hole-1.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02bba40d61a4453fff94bf41a4dd90d54bfd38ef4d033d3ea241c6064891f3a8",
                "md5": "0e3733a2cd1b90c3ef01ce3bbbe35a0a",
                "sha256": "12c42aac0d1d4f58b6a6e0a61a2f019b3452f4b52a8d6e11a4bb27ecef5d89ac"
            },
            "downloads": -1,
            "filename": "gh-rabbit-hole-1.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0e3733a2cd1b90c3ef01ce3bbbe35a0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 12995,
            "upload_time": "2024-01-01T05:34:29",
            "upload_time_iso_8601": "2024-01-01T05:34:29.926241Z",
            "url": "https://files.pythonhosted.org/packages/02/bb/a40d61a4453fff94bf41a4dd90d54bfd38ef4d033d3ea241c6064891f3a8/gh-rabbit-hole-1.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-01 05:34:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "m-ghiani",
    "github_project": "RABBIT_HOLE",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "gh-rabbit-hole"
}
        
Elapsed time: 0.15215s