标签:mes IV wait blocking 线程 received pre python3 import
RabbitMQ:
和python queue的区别
线程queue,多个线程之间数据同步用
进程queue,用于父进程与子进程交互,或同一父进程下多个子进程之间交互
rabbitmq,两个独立进程之间交互
依赖erlang
producer
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # -*- Author:Hinimix -*- import pika creditials = pika.PlainCredentials(‘admin‘, ‘Inspiry2018‘) conn = pika.BlockingConnection( pika.ConnectionParameters("192.168.20.61", 5672, ‘/‘, creditials) ) channel = conn.channel() #声明一个管道 channel.queue_declare(queue=‘hinimix‘) channel.basic_publish( exchange=‘‘, # routing_key=‘hinimix‘, #queue名字 body=‘hello, world‘ #内容 ) print("[x] sent ‘hello world") conn.close()
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # -*- Author:Hinimix -*- import pika creditials = pika.PlainCredentials(‘admin‘, ‘admin‘) conn = pika.BlockingConnection( pika.ConnectionParameters("192.168.20.61", 5672, ‘/‘, creditials) ) channel = conn.channel() #声明一个管道 channel.queue_declare(queue=‘hinimix‘) channel.basic_publish( exchange=‘‘, # routing_key=‘hinimix‘, #queue名字 body=‘hello, world‘ #内容 ) print("[x] sent ‘hello world") conn.close()
consumer
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # -*- Author:Hinimix -*- import pika creditials = pika.PlainCredentials(‘admin‘, ‘admin‘) conn = pika.BlockingConnection( pika.ConnectionParameters("192.168.20.61", 5672, ‘/‘, creditials) ) channel = conn.channel() channel.queue_declare(queue=‘hinimix‘) def callback(ch, method, properties, body): print(ch, ‘@@‘, method,‘@@‘, properties,‘@@‘, body) print("[x] received %r" % body) channel.basic_consume( callback, # 如果收到消息调用callback来处理消息 queue=‘hinimix‘, no_ack=True ) print("[*] waiting for messages.") channel.start_consuming()
标签:mes IV wait blocking 线程 received pre python3 import
原文地址:https://www.cnblogs.com/hinimix/p/9179535.html