Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' Consumer '''
- import pika
- class MegaIntrepidClass:
- awesome_attribute = None
- def callback_check_url(self, ch, method, properties, body):
- # Do something like the below
- # self.hold_it_against_me(body) # Obviously can't do this "as is".
- print(" [x] Received %r" % body)
- ch.basic_ack(delivery_tag=method.delivery_tag)
- def run(self):
- connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
- channel = connection.channel()
- channel.queue_declare(queue='queue', durable=True)
- channel.basic_consume(self.callback_check_url, queue='queue', no_ack=True)
- channel.start_consuming()
- if __name__ == "__main__":
- mic = MegaIntrepidClass()
- mic.run()
- ''' Producer '''
- import pika
- if __name__ == "__main__":
- connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
- channel = connection.channel()
- channel.queue_declare(queue='queue', durable=True)
- channel.basic_publish(exchange='', routing_key='queue', body='Hello World!')
- print(" [x] Sent!")
- connection.close()
Add Comment
Please, Sign In to add comment