Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pika
- from multiprocessing import Pool
- def worker(message):
- print(message)
- def main():
- connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
- channel = connection.channel()
- pool = Pool(processes=2)
- def callback(ch, method, properties, body):
- message = body.decode()
- pool.apply_async(worker, (message,))
- channel.basic_consume(
- queue='hello',
- on_message_callback=callback,
- )
- channel.start_consuming()
- pool.close()
- pool.join()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement