Skip to content

Instantly share code, notes, and snippets.

@idettman
Last active February 28, 2020 02:56
Show Gist options
  • Save idettman/360d47b258ba6c228a1de02d66d28811 to your computer and use it in GitHub Desktop.
Save idettman/360d47b258ba6c228a1de02d66d28811 to your computer and use it in GitHub Desktop.
python pika threading example
def receive_command():
print("ENTERED")
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
print("1")
channel = connection.channel()
print("2")
channel.exchange_declare(exchange='STORE_CMD', type='topic')
print("3")
result = channel.queue_declare(exclusive=True)
print("4")
queue_name = result.method.queue
print("5")
def callback_rabbit(ch,method,properties,body):
print("RICEVUTO MSG: RKEY:"+method.routing_key+" MSG: "+body+"\n")
print("6")
channel.queue_bind(exchange='STORE_CMD', queue=queue_name , routing_key='test.routing.key')
print("7")
channel.basic_consume(callback_rabbit,queue=queue_name,no_ack=True)
print("8")
channel.start_consuming()
def start():
t_msg = threading.Thread(target=receive_co
t_msg.join(0)
#self.receive_command()
start()
def receive_command():
print("ENTERED")
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
print("1")
channel = connection.channel()
print("2")
channel.exchange_declare(exchange='STORE_CMD', type='topic')
print("3")
result = channel.queue_declare(exclusive=True)
print("4")
queue_name = result.method.queue
print("5")
def callback_rabbit(ch,method,properties,body):
print("RICEVUTO MSG: RKEY:"+method.routing_key+" MSG: "+body+"\n")
print("6")
channel.queue_bind(exchange='STORE_CMD', queue=queue_name , routing_key='test.routing.key')
print("7")
channel.basic_consume(callback_rabbit,queue=queue_name,no_ack=True)
print("8")
channel.start_consuming()
def start():
t_msg = threading.Thread(target=receive_command)
t_msg.start()
t_msg.join(0)
#self.receive_command()
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment