网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

rabbitmq远程消费者生产者发送端接收端实例-创新互联

rabbit_remote_send_procedure.py

创新互联长期为上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为长垣企业提供专业的网站设计、做网站,长垣网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。

#!_*_coding:utf-8_*_
importpika
credentials=pika.PlainCredentials('lwb','123456')

connection = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.81.100',port=5672,virtual_host='/',credentials=credentials))#rabbit默认端口5672 建立一个基本的 socket连接
channel = connection.channel()#声明一个管道 在管道里面发消息

# 声明queue
channel.queue_declare(queue='hello5')

# n RabbitMQ a message can never be sent directly to the queue, it always needs to go through an exchange.
channel.basic_publish(exchange='',
                      routing_key='hello5',#queue名字
                      body='Hello World!') #body 发送的消息
print(" [x] Sent 'Hello World!'")
connection.close()

rabbitmq_recive_consumer.py


#!_*_coding:utf-8_*_
__author__ = 'Alex Li'
import
pika
credentials=pika.PlainCredentials('lwb','123456')
connection = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.81.100',port=5672,virtual_host='/',credentials=credentials)) #rabbit默认端口5672 建立一个基本的 socket连接
channel = connection.channel()#声明一个管道 在管道里面收消息

# You may ask why we declare the queue again ‒ we have already declared it in our previous code.
# We could avoid that if we were sure that the queue already exists. For example if send.py program
# was run before. But we're not yet sure which program to run first. In such cases it's a good
# practice to repeat declaring the queue in both programs.
channel.queue_declare(queue='hello1')#声明queue


defcallback(ch, method, properties, body):
    print("---->",ch,method,properties)#ch 管道内存对象地址 method:发给queue的信息
    print(" [x] Received %r"% body)


channel.basic_consume(#消费消息
                      callback,#如果收到消息,就调用CALLBACK函数来处理消息
                      queue='hello1',#从哪个队列里收消息
                      no_ack=True
)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()#启动 开始收消息 一直收,没有就卡主

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享文章:rabbitmq远程消费者生产者发送端接收端实例-创新互联
当前链接:http://bjjierui.cn/article/dcdccs.html

其他资讯