小编Gab*_*abe的帖子

使用RabbitMQ接收消息,然后对其进行处理,然后发送回结果

我想直接从脚本发送一条消息,然后对其进行处理,然后将结果发送回去。因此,这就像一个双重发布-订阅。

我有2个脚本:

  • 处理机
  • 客户

客户端直接向处理程序发送一条消息(简单字符串),然后,Processer脚本对字符串中的字符进行计数,然后将结果发送回客户端。

这是我尝试做的事情:

处理程序等待消息,计算出一些内容,然后将答案返回给原始发件人。

#Processer.py:
import pika
import sys

#Sends back the score
#addr: Connection address
#exchName: Exchange name (where to send)
#rKey: Name of the queue for direct messages
#score: The detected score
def SendActualScore(addr, exchName, rKey, score):
    #Send the image thru the created channel with the given routing key (queue name)
    channel.basic_publish(exchange=exchName, routing_key=rKey, body=score)
    print "(*) Sent: " + score

#When we receive something this is called
def CallbackImg(ch, method, properties, body):
    print "(*) Received: …
Run Code Online (Sandbox Code Playgroud)

python rabbitmq

5
推荐指数
1
解决办法
2546
查看次数

标签 统计

python ×1

rabbitmq ×1