真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

rabbitmq遠(yuǎn)程消費(fèi)者生產(chǎn)者發(fā)送端接收端實(shí)例

rabbit_remote_send_procedure.py

成都創(chuàng)新互聯(lián)專注于無極網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供無極營銷型網(wǎng)站建設(shè),無極網(wǎng)站制作、無極網(wǎng)頁設(shè)計、無極網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)公司服務(wù),打造無極網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供無極網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

#!_*_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默認(rèn)端口5672 建立一個基本的 socket連接
channel = connection.channel()#聲明一個管道 在管道里面發(fā)消息

# 聲明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 發(fā)送的消息
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默認(rèn)端口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 管道內(nèi)存對象地址 method:發(fā)給queue的信息
    print(" [x] Received %r"% body)


channel.basic_consume(#消費(fèi)消息
                      callback,#如果收到消息,就調(diào)用CALLBACK函數(shù)來處理消息
                      queue='hello1',#從哪個隊(duì)列里收消息
                      no_ack=True
                     
)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()#啟動 開始收消息 一直收,沒有就卡主


本文名稱:rabbitmq遠(yuǎn)程消費(fèi)者生產(chǎn)者發(fā)送端接收端實(shí)例
URL分享:http://weahome.cn/article/ggeogs.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部