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
  • 相关阅读:
    软件质量见解
    Vim 简明教程【转载】
    Actor Mailbox
    Unity对齐工具
    静态AOP Fody PropertyChanged
    棋牌分布式架构
    死锁
    curl 获取自定义数据
    WPF RichTextBox添加一条有颜色的记录
    arp -s 添加失败:拒绝访问
  • 原文地址:https://www.cnblogs.com/liu1026/p/7688785.html
Copyright © 2011-2022 走看看