Skip to content

Instantly share code, notes, and snippets.

@gmr
Last active August 29, 2015 14:02
Show Gist options
  • Save gmr/bae19e646852c8f2b5fa to your computer and use it in GitHub Desktop.
Save gmr/bae19e646852c8f2b5fa to your computer and use it in GitHub Desktop.
Dump N messages into a linefeed delimited file from a queue
import rabbitpy
MSG_COUNT = 100
FILENAME = 'messages.dump'
with rabbitpy.Connection('amqp://guest:guest@localhost:5672/%2f') as conn:
with conn.channel() as channel:
queue = rabbitpy.Queue(channel, 'example')
count = 0
with open(FILENAME, 'wb') as handle:
for message in queue.consume_messages():
handle.write(message.body + '\n')
count += 1
if count == MSG_COUNT:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment