zoukankan      html  css  js  c++  java
  • 使用Python 、 go 语言测试rabbitmq的工作机制

    1:在haproxy 和 rabbitmq上安装Python、python2-pip,默认是Python2
    yum install -y python python2-pip
     
    2:在haproxy 和 rabbitmq上使用pip安装pika库
    pip install pika==0.9.8
     
    3:在haproxy上写一个Python发送消息代码
    vi send.py
    -------
    #!/usr/bin/env python
    import pika
    connection = pika.BlockingConnection(pika.ConnectionParameters(
    host='localhost'))
    channel = connection.channel()
    channel.queue_declare(queue='hello')
    channel.basic_publish(exchange='',
    routing_key='hello',
    body='Hello Uplooking!')
    print "Sent 'Hello Uplooking!'"
    connection.close()
    -------
     
    4:在rabbitmq上写一个Python接受消息代码
    vi receive.py
    -------
    #!/usr/bin/env python
    import pika
    connection = pika.BlockingConnection(pika.ConnectionParameters(
    host='localhost'))
    channel = connection.channel()
    channel.queue_declare(queue='hello')
    print ' waiting for messages! press CTRL+C to halt'
    def callback(ch, method, properties, body):
    print "Received %r" % (body,)
    channel.basic_consume(callback,
    queue='hello',
    no_ack=True)
    channel.start_consuming()
    -------
     
    5:先运行receive.py,在运行send.py
    python receive.py
    python send.py
  • 相关阅读:
    CF Hello 2020 E.New Year and Castle Construction
    HTML 简介
    グランドエスケープ
    CF 1244 C
    N皇后解法以及位运算优化
    CF
    动态规划TG.lv(1) (洛谷提高历练地)
    搜索Ex (洛谷提高历练地)
    数字图像处理——图像增强
    数字图像处理——图像的几何变换
  • 原文地址:https://www.cnblogs.com/liu1026/p/7688785.html
Copyright © 2011-2022 走看看