Skip to content

Instantly share code, notes, and snippets.

@fjallstrom
Last active December 12, 2015 03:18
Show Gist options
  • Save fjallstrom/4705614 to your computer and use it in GitHub Desktop.
Save fjallstrom/4705614 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import pika
import time
credentials = pika.credentials.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters(
host="127.0.0.1",
credentials=credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='jobs', durable=True, auto_delete=True)
print ' [*] Waiting for messages. To exit press CTRL+C'
def callback(ch, method, properties, body):
print " [x] Received %r" % (body,)
time.sleep( body.count('.') )
print " [x] Done"
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback, queue='jobs')
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment