1. 程式人生 > >python第五十七天-- 補上筆記

python第五十七天-- 補上筆記

-- python rop bsp hello cal locking sta min

RabbitMQ隊列:

發送端:

技術分享
 1 #!usr/bin/env python
 2 #-*-coding:utf-8-*-
 3 # Author calmyan 
 4 #python 
 5 #2017/6/26    16:08
 6 #__author__=‘Administrator‘
 7 import pika
 8 connetion =pika.BlockingConnection(
 9     pika.ConnectionParameters(localhost)#創建連接
10 )
11 chann_1=connetion.channel()#生成一個管道
12 
13
chann_1.queue_declare(queue=hello)#生成對列 14 15 chann_1.basic_publish(exchange=‘‘,# 16 routing_key=hello,#使用的對列 17 body=發送的內容.... 18 ) 19 print([xxx]:發送了內容....) 20 connetion.close()#關閉連接
View Code

接收端:

技術分享
 1 #!usr/bin/env python
 2
#-*-coding:utf-8-*- 3 # Author calmyan 4 #python 5 #2017/6/26 18:28 6 #__author__=‘Administrator‘ 7 import pika 8 connetion =pika.BlockingConnection( 9 pika.ConnectionParameters(localhost)#創建連接 10 ) 11 chann_1=connetion.channel()#生成一個管道 12 13 chann_1.queue_declare(queue=hello)#生成對列
14 15 def callback(ch,method,properties,body): 16 print(ch,method,properties)#ch 管道內存對象, method ,隊列等 信息 17 print([xxx] 回調函數的內容 %r%body.decode()) 18 19 chann_1.basic_consume(#收消息 20 callback,#如果收到消息就調用 函數 21 queue=hello,#收消息的對列 22 no_ack=True# 23 ) 24 print(運行一直收消息, Ctrl+C 退出!) 25 chann_1.start_consuming()#開始接收消息
View Code

python第五十七天-- 補上筆記