zoukankan      html  css  js  c++  java
  • python第五十七天-- 补上笔记

    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
  • 相关阅读:
    0环与3环通信
    NACTF Encoder
    内核空间与内核模块
    Reserve ctf SSE_KEYGENME VAX2学习
    Inf2Cat Tool Output: ........................ Signability test failed.
    wustctf2020_closed
    ciscn_2019_final_5
    ciscn_2019_en_3 tcache
    内核编程基础
    保护模式阶段测试说明
  • 原文地址:https://www.cnblogs.com/uge3/p/7214229.html
Copyright © 2011-2022 走看看