美文网首页
rabbitmq02 模拟工作请求

rabbitmq02 模拟工作请求

作者: 6c0fe9142f09 | 来源:发表于2018-08-26 11:46 被阅读0次

模拟工作请求

1.发送消息
  • 使用input建立一个可以指定发送内容的sender
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters('XXXX'))
channel = connection.channel()

message = input("请输入发送内容:") or 'Hello World!'
channel.basic_publish(exchange='',
                     routing_key='hello',
                     body=message)

print('[X] Sent %r'%message)
2.接收消息
  • 每接收到1个点,我们就sleep1秒,来模拟真正的工作
import pika
import time

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

print ' [*] Waiting for messages. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] Received %r" % (body,)
    time.sleep(body.decode().count('.'))
    print " [x] Done"

channel.basic_consume(callback,
                      queue='hello',
                      no_ack=True)

channel.start_consuming()
3.开始试验吧
  • 开启两个worker
  • 发送消息观察worker中的内容
  • 可以看到rabbitmq会按照顺序把消息发送给每个消费者。默认采用一种轮询的方式

相关文章

  • rabbitmq02 模拟工作请求

    模拟工作请求 1.发送消息 使用input建立一个可以指定发送内容的sender 2.接收消息 每接收到1个点,我...

  • SpringBoot开发接口

    1、模拟get请求2、模拟get请求返回cookie3、模拟get请求携带cookie信息4、模拟get请求携带参...

  • 干货!接口测试中模拟post四种请求数据

    一、背景介绍 在日常的接口测试工作中,模拟接口请求通常有两种方法,fiddler模拟和HttpClient模拟。 ...

  • Python 爬虫知识记——基础篇

    简单的爬虫请求: 这样就会获取到指定网页的数据了。 GET 请求模拟 post 请求模拟 headers 请求头设...

  • Future函数使用

    Future常用方法: 多个网络请求同时进行: await、async模拟异步网路请求: Future模拟异步网络请求:

  • iOS请求方法和网络安全

    GET和POST请求 GET和POST请求简介 GET请求模拟登陆 POST请求模拟登陆 GET和POST的对比 ...

  • moco带cookie和headers请求

    moco可以接收带模拟cookie的请求,也可以模拟返回携带cookie的请求添加cookie和headers请求...

  • 命令行curl模拟get post请求

    新学到一个小技巧,在命令行中模拟get、post请求 模拟post请求 模拟post请求,在命令行中输入:-d代表...

  • iOS请求方法和网络安全

    GET和POST请求GET和POST请求简介GET请求模拟登陆POST请求模拟登陆GET和POST的对比保存用户信...

  • 1.web爬虫,requests请求

    requests请求,就是用python的requests模块模拟浏览器请求,返回html源码 模拟浏览器请求有两...

网友评论

      本文标题:rabbitmq02 模拟工作请求

      本文链接:https://www.haomeiwen.com/subject/ldfoiftx.html