zoukankan      html  css  js  c++  java
  • w11_mq.md

    [TOC]


    #Python3.5-RabbitMQ基本示例

    producer.py
    ```

    import pika
    
    connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
    channel = connection.channel()
    
    channel.queue_declare(queue='hello')
    
    channel.basic_publish(exchange='',
                          routing_key='hello',
                          body='{"name":"alex"}')
    print(" [x] Sent 'Hello World!'")
    connection.close()
    

      

    ```

    consumer.py

    ```

    import pika
    import json
    
    connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
    channel = connection.channel()
    
    channel.queue_declare(queue='hello')
    
    
    
    def callback(ch, method, properties, body):
        print(" [x] Received %r" % body)
        body = json.loads(body.decode("utf-8"))
        print(type(body))
        print("body['name']=%s" % body["name"] )
    
    channel.basic_consume(callback,
                          queue='hello',
                          no_ack=True)
    print(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()
    

      

    ```

    [返回顶部](#top)

    #Python3.5-RabbitMQ消息分发轮询

    ```

    durable = True #make queue persistent
    delivery_mode = 2 #make message persistent

    ```

    refer:http://www.cnblogs.com/alex3714/articles/5248247.html

  • 相关阅读:
    JdbcTemplate
    Spring AOP——基于XML的进阶案例
    Spring
    面试题
    切面编程
    选择题
    Spring核心概念
    缓存
    BFC 神奇背后的原理
    git 教程
  • 原文地址:https://www.cnblogs.com/rootid/p/9727022.html
Copyright © 2011-2022 走看看