1

I'm trying to write some tests where I produce a message to a queue and see if the message gets correctly consumed and handled in the application.

For that I'm playing around with the kombu library and especially the in-memory Transport implementation.

Still I can't get it working, that the produced message gets consumed.

My questions is therefore, if anyone can provide a simple unit test that produces and consumes a message in-memory

c4pone
  • 777
  • 7
  • 17

1 Answers1

3

You'll want to adapt this to the code you're trying to test, but the basic thing you are looking for is the amqp URI for the in-memory controller, which is 'memory://'. As a really simple example:

conn = kombu.Connection("memory://")
queue = conn.SimpleQueue('myqueue')
queue.put('test')
msg = queue.get(timeout=1)
msg.ack()
print(msg.payload)
pwlars
  • 516
  • 5
  • 4