Package: amqp-rpc-client
AMQP RPC ClientThis 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 packagepikais only
tested with the RabbitMQ serverUsageGeneralThis 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 libraryExamplesCreate a new clientfromamqp_rpc_clientimportClient# The Data Source Name which is used to connect to the message broker. The virtual host currently# is "/". Special characters need to be url-encodedAMQP_DSN='amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'# Create the new client with the data source namerpc_client=Client(AMQP_DSN)Send a message to another exchangefromamqp_rpc_clientimportClient# The Data Source Name which is used to connect to the message broker. The virtual host currently# is "/". Special characters need to be url-encodedAMQP_DSN='amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'# The exchange into which the message shall be postedTARGET_EXCHANGE='hello_world'# Create the new client with the data source namerpc_client=Client(AMQP_DSN)# Send a message to the specified exchangerpc_client.send('my_message_content_string',TARGET_EXCHANGE)Send a message to another exchange and wait for the answerfromamqp_rpc_clientimportClient# The Data Source Name which is used to connect to the message broker. The virtual host currently# is "/". Special characters need to be url-encodedAMQP_DSN='amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'# The exchange into which the message shall be postedTARGET_EXCHANGE='hello_world'# Create the new client with the data source namerpc_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 responsemessage_id=rpc_client.send('my_message_content_string',TARGET_EXCHANGE)# Wait indefinitely and receive the response bytesresponse:bytes=rpc_client.await_response(message_id)Send a message to another exchange and wait for the answer with an timeoutfromamqp_rpc_clientimportClient# The Data Source Name which is used to connect to the message broker. The virtual host currently# is "/". Special characters need to be url-encodedAMQP_DSN='amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'# The exchange into which the message shall be postedTARGET_EXCHANGE='hello_world'# The timeout in seconds as to how long the answer shall be awaitedANSWER_TIMEOUT:float=10.0# Create the new client with the data source namerpc_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 responsemessage_id=rpc_client.send('my_message_content_string',TARGET_EXCHANGE)# Wait indefinitely and receive the response bytesresponse:bytes=rpc_client.await_response(message_id,ANSWER_TIMEOUT)# Check if a response was receivedifresponseisNone:print('No response received')else:print(response)Directly get the response content if it is availablefromamqp_rpc_clientimportClient# The Data Source Name which is used to connect to the message broker. The virtual host currently# is "/". Special characters need to be url-encodedAMQP_DSN='amqp://<<your-username>>:<<your-password>>@<<your-message-broker-address>>/%2F'# The exchange into which the message shall be postedTARGET_EXCHANGE='hello_world'# The timeout in seconds as to how long the answer shall be awaitedANSWER_TIMEOUT:float=10.0# Create the new client with the data source namerpc_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 responsemessage_id=rpc_client.send('my_message_content_string',TARGET_EXCHANGE)# Try to get the responseresponse:bytes=rpc_client.get_response(message_id)# Check if a response was receivedifresponseisNone:print('No response received')else:print(response)