Advertisement
kopyl

Untitled

Jan 23rd, 2024 (edited)
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import pika
  2. from multiprocessing import Pool
  3.  
  4.    
  5. def worker(message):
  6.     print(message)
  7.  
  8.  
  9. def main():
  10.     connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
  11.     channel = connection.channel()
  12.  
  13.     pool = Pool(processes=2)
  14.  
  15.     def callback(ch, method, properties, body):
  16.         message = body.decode()
  17.         pool.apply_async(worker, (message,))
  18.  
  19.     channel.basic_consume(
  20.         queue='hello',
  21.         on_message_callback=callback,
  22.     )
  23.  
  24.     channel.start_consuming()
  25.  
  26.     pool.close()
  27.     pool.join()
  28.  
  29.  
  30. if __name__ == '__main__':
  31.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement