django2/demo/app/queue/ampq_receiver.py
Peter Kotyczka 679d7d1b58 smc
2024-03-24 22:58:33 +01:00

29 lines
785 B
Python
Executable File

import optparse
import time
import os
import sys
from proton import Message
from proton.utils import BlockingConnection
from proton.handlers import IncomingMessageHandler
broker = '5672' ##os.getenv('AMQP_BROKER_HOST_PORT')
queue = 'proton' ##os.getenv('AMQP_ADDRESS')
user_arg = 'smx' ##os.getenv('AMQP_USER')
userpw_arg = 'smx' ##os.getenv('AMQP_USER_PASSWORD')
conn = BlockingConnection(broker, user=user_arg, password=userpw_arg)
receiver = conn.create_receiver(queue)
count = 0
try:
while True:
msg = receiver.receive(timeout=None)
count += 1
print("got message, processing for two seconds...")
sys.stdout.flush()
time.sleep(2)
receiver.accept()
finally:
conn.close()
print ("All done. Processed ", count, " messages.")