Last active
February 28, 2020 02:56
-
-
Save idettman/360d47b258ba6c228a1de02d66d28811 to your computer and use it in GitHub Desktop.
python pika threading example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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