zoukankan      html  css  js  c++  java
  • rabbitmq使用__python客户端(消息接收者)

    #! /usr/bin/python
    # -*- coding: utf-8 -*- 
    
    import amqplib.client_0_8 as amqp
    
    # 创建一个TCP 连接
    conn = amqp.Connection(host="localhost:5672 ", userid="guest",  password="guest", virtual_host="/", insist=False)
    # 创建一个通信channel 
    chan = conn.channel()
    # 创建一个队列 
    chan.queue_declare(queue="po_box", durable=True,  exclusive=False, auto_delete=False)
    # 创建一个交换机
    chan.exchange_declare(exchange="sorting_room", type="direct", durable=True, auto_delete=False)
    # 绑定
    chan.queue_bind(queue="po_box", exchange="sorting_room",routing_key="jason")
    
    def recv_callback(msg):
        print 'Received: ' + msg.body + ' from channel #' + str(msg.channel.channel_id)
    
    chan.basic_consume(queue='po_box', no_ack=True,  callback=recv_callback, consumer_tag="testtag")
    
    while True:
        chan.wait()
    
    # 该句不会执行
    chan.basic_cancel("testtag")
    
    chan.close()
    conn.close()
  • 相关阅读:
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I作业11
    C语言I作业10
    C语言I作业09
    C语言I作业08
    C语言寒假大作战04
  • 原文地址:https://www.cnblogs.com/mingaixin/p/2743797.html
Copyright © 2011-2022 走看看