Skip to main content

An asynchronous RPC client for message brokers implementing the AMQPv0-9-1 protocol

Project description

AMQP RPC Client

CodeQL OSSAR Pylint

This library offers a Remote-Procedure-Call client which communicates its messages via a message broker which uses the AMQPv0-9-1 protocol.

This library is currently only tested with RabbitMQ since the underlying package pika is only tested with the RabbitMQ server

Usage

General

This AMQP RPC Client uses an extra thread in which it handles data events like new messages or sending keep-alive messages. Therefore, your code will continue to execute after sending a message without waiting for a response. See the attached examples for how to use the library

Examples

Create a new client
from amqp_rpc_client import Client

# The Data Source Name which is used to connect to the message broker. The virtual host currently
# is "/". Special characters need to be url-encoded
AMQP_DSN = 'amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'

# Create the new client with the data source name
rpc_client = Client(AMQP_DSN)
Send a message to another exchange
from amqp_rpc_client import Client

# The Data Source Name which is used to connect to the message broker. The virtual host currently
# is "/". Special characters need to be url-encoded
AMQP_DSN = 'amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'

# The exchange into which the message shall be posted
TARGET_EXCHANGE = 'hello_world'

# Create the new client with the data source name
rpc_client = Client(AMQP_DSN)

# Send a message to the specified exchange
rpc_client.send('my_message_content_string', TARGET_EXCHANGE)
Send a message to another exchange and wait for the answer
from amqp_rpc_client import Client

# The Data Source Name which is used to connect to the message broker. The virtual host currently
# is "/". Special characters need to be url-encoded
AMQP_DSN = 'amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'

# The exchange into which the message shall be posted
TARGET_EXCHANGE = 'hello_world'

# Create the new client with the data source name
rpc_client = Client(AMQP_DSN)

# Send a message to the specified exchange. This will return a message id which can be used to wait
# for a response
message_id = rpc_client.send('my_message_content_string', TARGET_EXCHANGE)

# Wait indefinitely and receive the response bytes
response: bytes = rpc_client.await_response(message_id)
Send a message to another exchange and wait for the answer with an timeout
from amqp_rpc_client import Client

# The Data Source Name which is used to connect to the message broker. The virtual host currently
# is "/". Special characters need to be url-encoded
AMQP_DSN = 'amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'

# The exchange into which the message shall be posted
TARGET_EXCHANGE = 'hello_world'

# The timeout in seconds as to how long the answer shall be awaited
ANSWER_TIMEOUT: float = 10.0

# Create the new client with the data source name
rpc_client = Client(AMQP_DSN)

# Send a message to the specified exchange. This will return a message id which can be used to wait
# for a response
message_id = rpc_client.send('my_message_content_string', TARGET_EXCHANGE)

# Wait indefinitely and receive the response bytes
response: bytes = rpc_client.await_response(message_id, ANSWER_TIMEOUT)

# Check if a response was received
if response is None:
    print('No response received')
else:
    print(response)
Directly get the response content if it is available
from amqp_rpc_client import Client

# The Data Source Name which is used to connect to the message broker. The virtual host currently
# is "/". Special characters need to be url-encoded
AMQP_DSN = 'amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'

# The exchange into which the message shall be posted
TARGET_EXCHANGE = 'hello_world'

# The timeout in seconds as to how long the answer shall be awaited
ANSWER_TIMEOUT: float = 10.0

# Create the new client with the data source name
rpc_client = Client(AMQP_DSN)

# Send a message to the specified exchange. This will return a message id which can be used to wait
# for a response
message_id = rpc_client.send('my_message_content_string', TARGET_EXCHANGE)

# Try to get the response
response: bytes = rpc_client.get_response(message_id)

# Check if a response was received
if response is None:
    print('No response received')
else:
    print(response)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amqp-rpc-client-1.2.6a5.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

amqp_rpc_client-1.2.6a5-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file amqp-rpc-client-1.2.6a5.tar.gz.

File metadata

  • Download URL: amqp-rpc-client-1.2.6a5.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for amqp-rpc-client-1.2.6a5.tar.gz
Algorithm Hash digest
SHA256 6b1ed610436982430aabbfea49e649215081c1f33182fd42ed90658d3897df6c
MD5 59e4db9ebdb667cf5cedec5add415ef1
BLAKE2b-256 26fbd1242b6eb841071e7bf57d7c4eb9a3f67a4024a13e9a488b8ce5a3326707

See more details on using hashes here.

File details

Details for the file amqp_rpc_client-1.2.6a5-py3-none-any.whl.

File metadata

File hashes

Hashes for amqp_rpc_client-1.2.6a5-py3-none-any.whl
Algorithm Hash digest
SHA256 81fb27dd7fbec595d65b5bae960fc9d005d75813270a4672a95669c83fdb0423
MD5 04d4e3d882214aaee985d339e8176148
BLAKE2b-256 5530054d18db09ea09527def95be65d2c67a7b374d85b0bb9bf41f3e4746d537

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page