Package: amqp-mock
AMQP MockInstallationOverviewTest PublishingTest ConsumingMock ServerStart serverPublish messageGet queue message historyGet exchange messagesDelete exchange messagesResetInstallationpip3installamqp-mockOverviewTest Publishingfromamqp_mockimportcreate_amqp_mock# 1. Start AMQP mock serverasyncwithcreate_amqp_mock()asmock:# 2. Publish message via "system under test"publish_message([1,2,3],"exchange")# 3. Test message has been publishedmessages=awaitmock.client.get_exchange_messages("exchange")assertmessages[0].value==[1,2,3]Full code available here:./examples/publish_example.pyTest Consumingfromamqp_mockimportcreate_amqp_mock,Message,MessageStatus# 1. Start AMQP mock serverasyncwithcreate_amqp_mock()asmock:# 2. Mock next messageawaitmock.client.publish_message("queue",Message([1,2,3]))# 3. Consume message via "system under test"consume_message("queue")# 4. Test message has been consumedhistory=awaitmock.client.get_queue_message_history("queue")asserthistory[0].status==MessageStatus.ACKEDFull code available here:./examples/consume_example.pyMock ServerStart serverimportasynciofromamqp_mockimportAmqpServer,HttpServer,Storage,create_amqp_mockasyncdefrun()->None:storage=Storage()http_server=HttpServer(storage,port=8080)amqp_server=AmqpServer(storage,port=5672)asyncwithcreate_amqp_mock(http_server,amqp_server):awaitasyncio.Future()asyncio.run(run())or via dockerdockerrun-p8080:80-p5672:5672tsv1/amqp-mockPublish messagePOST /queues/{queue}/messages{"id":"9e342ac1-eef6-40b1-9eaf-053ee7887968","value":[1,2,3],"exchange":"","routing_key":"","properties":null}HTTP$httpPOSTlocalhost/queues/test_queue/messages\value:='[1, 2, 3]'\exchange=test_exchange

HTTP/1.1200OK
Content-Length:0Content-Type:application/jsonPythonfromamqp_mockimportAmqpMockClient,Messagemock_client=AmqpMockClient()message=Message([1,2,3],exchange="test_exchange")awaitmock_client.publish_message("test_queue",message)Get queue message historyGET /queues/{queue}/messages/historyHTTP$httpGETlocalhost/queues/test_queue/messages/history

HTTP/1.1200OK
Content-Length:190Content-Type:application/json;charset=utf-8[{"message":{"exchange":"test_exchange","id":"94459a41-9119-479a-98c9-80bc9dabb719","properties":null,"routing_key":"","value":[1,2,3]},"queue":"test_queue","status":"ACKED"}]Pythonfromamqp_mockimportAmqpMockClientmock_client=AmqpMockClient()awaitmock_client.get_queue_message_history("test_queue")# [#   <QueuedMessage message=<Message value=[1, 2, 3], exchange='test_exchange', routing_key=''>,#                  queue='test_queue',#                  status=MessageStatus.ACKED># ]Get exchange messagesGET /exchanges/{exchange}/messagesHTTP$httpGETlocalhost/exchanges/test_exchange/messages

HTTP/1.1200OK
Content-Length:423Content-Type:application/json;charset=utf-8[{"exchange":"test_exchange","id":"63fd1646-bdc1-4baa-9780-e337a9ab109c","properties":{"app_id":"","cluster_id":"","content_encoding":"","content_type":"","correlation_id":"","delivery_mode":1,"expiration":"","headers":null,"message_id":"5ec9024c74eca2e419fd7e29f7be846c","message_type":"","priority":null,"reply_to":"","timestamp":null,"user_id":""},"routing_key":"","value":[1,2,3]}]Pythonfromamqp_mockimportAmqpMockClientmock_client=AmqpMockClient()messages=awaitmock_client.get_exchange_messages("test_exchange")# [#   <Message value=[1, 2, 3], exchange='test_exchange', routing_key=''># ]Delete exchange messagesDELETE /exchanges/{exchange}/messagesHTTP$httpDELETElocalhost/exchanges/test_exchange/messages

HTTP/1.1200OK
Content-Length:0Content-Type:application/jsonPythonfromamqp_mockimportAmqpMockClientmock_client=AmqpMockClient()awaitmock_client.delete_exchange_messages("test_exchange")ResetDELETE /HTTP$httpDELETElocalhost/

HTTP/1.1200OK
Content-Length:0Content-Type:application/jsonPythonfromamqp_mockimportAmqpMockClientmock_client=AmqpMockClient()awaitmock_client.reset()