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 website to list Shadowsocks proxies and check them periodically

Shadowmere An automatically tested list of Shadowsocks proxies. Motivation Collecting proxies around the internet is fun, but what if they stop workin

Jorge Alberto Díaz Orozco (Akiel) 29 Dec 21, 2022
Flashes keyboard leds on incoming/outgoing network packets

LED Net Capture Flashes keyboard leds on incoming/outgoing network packets Usage Requires root priviledges to run usage: ledcapture.py [-h] --keyboard

Dan Habot 56 Oct 27, 2022
Python 3 tool for finding unclaimed groups on Roblox. Supports multi-threading, multi-processing and HTTP proxies.

roblox-group-scanner Python 3 tool for finding unclaimed groups on Roblox. Supports multi-threading, multi-processing and HTTP proxies. Usage usage: s

h0nda 43 May 11, 2022
Modern Denial-of-service ToolKit for python

💣 Impulse Modern Denial-of-service ToolKit 💻 Main window 📡 Methods: Method Target Description SMS PHONE Sends a massive amount of SMS messages and

1 Nov 29, 2021
A simple chat room using socket and threading for handle multiple connections.

• Socket Chat Room was a little project for socket study. It works with a server handling the incoming connections from the clients. Clients send encoded messages while waiting for others clients mes

Guilherme de Oliveira 2 Mar 03, 2022
syncio: asyncio, without await

syncio: asyncio, without await asyncio can look very intimidating to newcomers, because of the async/await syntax. Even experienced programmers can ge

David Brochart 10 Nov 21, 2022
A Calendar subscribe server for python

cn-holiday-ics-server A calendar subscribe server 直接使用我搭建的服务 订阅节假日:https://cdxy.fun:9999/holiday 订阅调休上班:https://cdxy.fun:9999/workday 节假日和调休上班在一起的版本:h

CD 11 Nov 12, 2022
Ov3 - Easy common OpenVPN3 operations

ov3 Easy common OpenVPN3 operations Install ov3 requires Python3 and OpenVPN3 to

Yunus Bora Erciyas 6 Apr 25, 2022
Vent domain information retrieval tool, which is capable of retrieving customer information

Vent domain information retrieval tool, which is capable of retrieving customer information. This tool has been created for the purpose of complete education, Iam not responsible for any illegal acti

Md. Ridwanul Islam Muntakim 25 Dec 09, 2022
ip2domain - get ip to domain, Know the domian corresponding to the local network connection IP

What is Sometimes, we need to know what connections our local machine has, and what are their IP, domain name, program and parameters? get ip to domai

51pwn 4 Sep 30, 2022
jarbou3 is rat tool coded in python with C&C which can accept multiple connections from clients

jarbou3 Jarbou3 is rat tool with coded in python with C&C which can accept multi

youhacker55 108 Dec 29, 2022
A working cloudflare uam bypass !!

Dark Utilities - Cloudflare Uam Bypass Our Website https://over-spam.space/ ! Additional Informations The proxies type are http,https ... You need fas

Inplex-sys 26 Dec 14, 2022
API to establish connection between server and client

Socket-programming API to establish connection between server and client, socket.socket() creates a socket object that supports the context manager ty

Muziwandile Nkomo 1 Oct 30, 2021
A python socket.io client for Roboteur

Roboteur Client Example TODO Basic setup Install the requirements: $ pip install -r requirements.txt Run the application: $ python -m roboteur_client

Barry Buck 1 Oct 13, 2021
This is a simple python code to get the list of banned IP addresses from Fail2ban

Fail2ban Scripts Usage banned_list.py This script tries to get the banned list of IP addresses by Fail2ban for the service freeswitch. You can modify

Yehor Smoliakov 9 Dec 28, 2022
Connection package to a raspberry or any other machine using ssh, it simplifies the deployment scripts and monitoring.

Connection package to a raspberry or any other machine using ssh, it simplifies the deployment scripts and monitoring.

Dashstrom 7 Mar 29, 2022
test whether http(s) proxies actually hide your ip

Proxy anonymity I made this for other projects, to find working proxies. If it gets enough support and if i have time i might make it into a gui Repos

gxzs1337 1 Nov 09, 2021
A library for interacting with APNs and VoIP using HTTP/2.

kalyke A library for interacting with APNs and VoIP using HTTP/2. Installation kalyke requires python 3.6 or later. $ pip install kalyke-apns Usage AP

Yuya Oka 11 Dec 08, 2022
Python Scrcpy Client - allows you to view and control android device in realtime

Python Scrcpy Client This package allows you to view and control android device in realtime. Note: This gif is compressed and experience lower quality

LengYue 126 Jan 02, 2023
A simple electrical network analyzer, BASED ON computer-aided design.

Electrical Network Analyzer A simple electrical network analyzer. Given the oriented graph of the electrical network (circut), BASED ON computer-aided

Ahmad Abdulrahman 4 Oct 15, 2022