RabbitMQ asynchronous connector library for Python with built in RPC support

Overview

badge PyPI version fury.io codecov PyPI download month PyPI pyversions Ask Me Anything !

About

RabbitMQ connector library for Python that is fully integrated with the aio-pika framework.

Introduction

BunnyStorm is here to simplify working with RabbitMQ while using aio-pika. This library offers an asynchronous implementation of a RabbitMQ connector which is fully integrated with asyncio. BunnyStorm provides an all-in-one adapter with the following functionalities:

  1. publish - Publish a message.
  2. receive - Consume messages from a queue. Can automatically reply to desired routes if the received message contains a "reply_to" property.
  3. rpc - Implement RPC (Remote procedure call) logic using RabbitMQ. Publish a message with a reply_to property, wait for a reply message and return the reply's content.

Installation

pip install -U bunny_storm

Examples

Simple Receiver (print messages from queue)

import asyncio
from bunny_storm import AsyncAdapter, RabbitMQConnectionData

RABBIT_URI = "amqp://guest:[email protected]:5672/"

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    configuration = dict(
        publish=dict(
            exchange="some_ex",
            exchange_type="direct",
            routing_key="some_rk",
        ),
        receive=dict(
            exchange="some_receive_ex",
            exchange_type="direct",
            routing_key="some_rk",
            queue="some_q",
        )
    )
    connection_data = RabbitMQConnectionData(username="guest", password="guest", connection_name="example")
    adapter = AsyncAdapter(rabbitmq_connection_data=connection_data, configuration=configuration, loop=loop)
    loop.create_task(adapter.receive(handler=lambda msg: print(msg.body), queue="some_q"))
    loop.run_forever()

Full Microservices Using RPC pattern

Example of 2 Microservices implementing a fully scalable application that calculates a number in the Fibonacci series while implementing RabbitMQ Remote procedure call (RPC) pattern, can be found at the examples directory.

Class Diagram

Class Diagram

Architecture

  1. RabbitMQConnectionData - A simple dataclass which contains all the relevant credentials and parameters necessary for opening a connection to a RabbitMQ server.

  2. AsyncConnection - A class responsible for the management of a single connection to a RabbitMQ server. The class connects to a server whose credentials are specified in a RabbitMQConnectionData object passed to it. The main function of this class is get_connection which uses aio-pika to open a robust connection to the server.

  3. ChannelConfiguration - A class which manages a single channel within a given RabbitMQ connection. This class encapsulates an AsyncConnection object, and exposes functionality to declare exchanges and queues. This class receives a connection (AsyncConnection from the previous paragraph) and parameters relevant to the creation of the channel.

  4. Publisher - A class which creates and uses a ChannelConfiguration object to publish messages to a given exchange. Automatically declares the desired exchange with various configurable parameters, such as exchange type. The main function of this class is publish, which ensures that the instance's channel is open and that the relevant exchange has been declared, following which, it publishes a message to the exchange.

  5. Consumer - A class which creates and uses a ChannelConfiguration object to consume messages from a given queue. Automatically declares the desired queue, and optionally an exchange as well, with various configurable parameters. The main functionality of this class is consume, which ensures that the instance's channel is open and that the relevant queue and exchange have been declared and bound as desired, following which, it consumes messages from the queue.

  6. AsyncAdapter - A class which exposes all the desired functionality for this framework:

    1. publish: Publish a message to a given exchange.
    2. receive: Receive messages from a given queue. Messages received which have their reply_to parameter set will automatically have a response sent to them containing the message handler's result.
    3. rpc: Perform an RPC by publishing a message with its reply_to parameter set to the relevant value.

    To perform these operations, each adapter instance receives a RabbitMQConnectionData instance, which is used to create a AsyncConnection instance. This is in turn used to create the Publisher and Consumer instances necessary to work with the queues and exchanges specified in the configurations given to the AsyncAdapter in its constructor. Each instance of the class also maintains a dictionary of correlation IDs relevant to messages we are waiting on a response for, namely RPC requests.

Todo

  • Implement Prometheus metrics support.
  • Server example - refactor it to render real HTML

Notes

This package is inspired by various implementations that I have encountered over the years. The current version includes improvements and adjustments designed to improve integration with technologies and frameworks developed over the last few years:

  • Python 3.9
  • aio-pika 6.8.0
  • RabbitMQ Server 3.8.3 on Ubuntu 18
A TCP Chatroom built with python and TCP/IP sockets, consisting of a server and multiple clients which can connect with the server and chat with each other.

A TCP Chatroom built with python and TCP/IP sockets, consisting of a server and multiple clients which can connect with the server and chat with each other. It also provides an Admin role with featur

3 May 22, 2022
A network address manipulation library for Python

netaddr A system-independent network address manipulation library for Python 2.7 and 3.5+. (Python 2.7 and 3.5 support is deprecated). Provides suppor

711 Jan 05, 2023
School Project using Python Sockets and Personal Encryption Method.

Python-Secure-File-Transfer School Project using Python Sockets and Personal Encryption Method. Installation Must have python3 installed on your syste

1 Dec 03, 2021
MQTT Explorer - MQTT Subscriber client to explore topic hierarchies

mqtt-explorer MQTT Explorer - MQTT Subscriber client to explore topic hierarchies Overview The MQTT Explorer subscriber client is designed to explore

Gambit Communications, Inc. 4 Jun 19, 2022
Tool for ROS 2 IP Discovery + System Monitoring

Monitor the status of computers on a network using the DDS function of ROS2.

Ar-Ray 33 Apr 03, 2022
Apple Store Stock Notifier monitors the availability of selected Apple devices in selected Apple stores, and sends you a notification when devices are available!

Apple Store Stock Notifier This software will immediately send you a notification via Telegram when one of your coveted Apple Devices is available in

Floris-Jan Willemsen 25 Dec 05, 2022
EUserv - A Python script which can help you renew your free EUserv IPv6 VPS

English | 简体中文 This project comes from https://github.com/a-beam-of-light/eu_ex

阿两 0 Jan 06, 2022
A simple DHCP server and client simulation with python

About The Project This is a simple DHCP server and client simulation. I implemented it for computer network course spring 2021 The client can request

shakiba 3 Feb 08, 2022
Aiotor - a pool of proxies, shifting on each request

Aiotor - a pool of proxies, shifting on each request

Leon 32 Dec 26, 2022
A tiny end-to-end latency testing tool implemented by UDP protocol in Python 📈 .

udp-latency A tiny end-to-end latency testing tool implemented by UDP protocol in Python 📈 . Features Compare with other existing latency testing too

Chuanyu Xue 5 Dec 02, 2022
API for concurrency connections

Multi-connection-server-API API for concurrency connections difference between this server and the echo server is the call to lsock.setblocking(False)

Muziwandile Nkomo 1 Jan 04, 2022
Very simple FTP client, sync folder to FTP server, use python, opensource

ftp-sync-python Opensource, A way to safe your data, avoid lost data by Virus, Randsomware Some functions: Upload a folder automatically to FTP server

4 Sep 13, 2022
The best way to send tokens into a specific server, which can be used for discord bots, and some tools..

XTRA420 The simplified version of sending tokens into a server, the basic and fastest way.. When using this, you have the option to use proxies (http)

07v 1 Nov 30, 2021
TunnelProxy 是一个本地隧道代理,可以从fofa爬取免费的socks代理,然后构建代理池,如果一个代理失效,会自动切换

TunnelProxy 是一个本地隧道代理,可以从fofa爬取免费的socks代理,然后构建代理池,如果一个代理失效,会自动切换。 应用场景 渗透测试需要访问某些国内网站(比如edu的),想要隐藏自己,但是国外代理不能访问,也没有稳定的可用代理的时候。 之后,可能我会增加国外代理,实现白嫖科学上网。

urdr-gungnir 45 Nov 17, 2022
pfSense integration with Home Assistant

hass-pfsense Join pfSense with home-assistant! hass-pfsense uses the built-in xmlrpc service of pfSense for all interactions. No special plugins or so

Travis Glenn Hansen 105 Dec 24, 2022
Autopen is a very modular tool that automates the execution of scans during a penetration test.

Autopen Autopen is a very modular tool that automates the execution of scans during a penetration test. A Nmap scan result in the form of an XML file

2 Dec 22, 2021
An automatic web reconnaissance tool written in python3.

WebRecon is an automatic web reconnaissance tool written in python3. Provides a command line interaction similar to msfconsole. The Exasmple.py file is provided, and you can write your own scripts yo

prophet 1 Feb 06, 2022
Caching for HTTPX

Caching for HTTPX. Note: Early development / alpha, use at your own risk. This package adds caching functionality to HTTPX Adapted from Eric Larson's

Mehul Solanki 0 Oct 08, 2022
TLD records archive. Revisiting the original TLDR project by mandatoryprogrammer, on the hunt for more root nameserver changes.

tldr A(nother) continuously updated historical TLD records archive. This repository is updated approximately every three hours with the results from D

Chris Partridge 11 Dec 14, 2022
A repository dedicated to IoT(internet of things ) and python scripts

📑 Introduction Week of Learning is a weekly program in which you will get all the necessary knowledge about Circuit-Building, Arduino and Micro-Contr

27 Nov 22, 2022