Advertisement
Ilya_Bykonya

Untitled

May 30th, 2024
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | Source Code | 0 0
  1. import pika
  2. import json
  3. import time
  4. import sys
  5.  
  6. def handle_incoming_message(channel, method, properties, body) ->None:
  7.     print(f'[{channel}][{method}][{properties}][{body}]')
  8.     channel.basic_ack(delivery_tag = method.delivery_tag)
  9.  
  10.  
  11. if __name__ == '__main__':
  12.     credentials = pika.credentials.PlainCredentials(username = 'guest', password = 'guest')
  13.     with pika.BlockingConnection(parameters = pika.ConnectionParameters(host = '127.0.0.1', port = 6666, credentials = credentials)) as connection:
  14.         with connection.channel() as channel:
  15.             channel.basic_qos(prefetch_count = 1, global_qos = False)
  16.             channel.basic_consume(queue = 'data-stream-000', on_message_callback = handle_incoming_message, arguments = {
  17.                 'single-active-consumer': True,
  18.                 'name': 'consumer-group-1'
  19.             })
  20.             channel.start_consuming()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement