在扇出交换上等待所有rabbitmq响应吗? [英] Waiting for all rabbitmq responses on a fanout exchange?

查看:85
本文介绍了在扇出交换上等待所有rabbitmq响应吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为RPC工作负载配置了Rabbitmq扇出交换,称为"ex_foo".客户端连接到服务器时,它们将创建自己的非持久RPC接收队列,并使用BasicConsumer连接到该队列.这些应用程序侦听消息/命令,并响应在请求的reply_to部分中定义的队列.

I've configured a rabbitmq fanout exchange called "ex_foo" for a RPC workload. When clients connect to the server, they create their own non-durable RPC receive queue and connect to it with a BasicConsumer. The apps listen for messages/commands and respond to the queue defined in the reply_to part of the request.

我发送扇出交换的一个简单消息/命令(因此,连接到它的每个应用程序/客户端)都是一种 ping请求消息,而我的问题是我不知道会收到多少ping响应(或应该预期),因为我不知道一次有多少个客户端连接到扇出交换机.连接到扇出交换机的所有客户端都应答复.

One of the simple messages/commands I'm sending out the the fanout exchange (and thus, every application/client connected to it) is a type of ping request message, and my problem is that I don't know how many ping responses I will get (or should expect), because I don't know how many clients are connected to the fanout exchange at any one time. All clients connected to the fanout exchange should reply.

如果在扇出交换机上传递到10个队列(即:已连接10个客户端),我如何知道期望多少响应?为了知道这一点,我是否必须知道交付了多少次?还有更复杂的功能和一个睡眠计时器吗?简而言之,我的管理工具不能无限期地等待,并且必须在收到所有ping命令后退出()(或超时).

If gets delivered to 10 queues on the fanout exchange (ie: 10 clients are connected), how do I know how many responses to expect? In order to know that, would I have to know how many times it was delivered? Is there anything more sophisticated and a sleep timer? Simply, my admin tool can't just wait indefinitely and needs to quit after it has recveived all pings (or a time-out has elapsed).

推荐答案

您正在寻找的是类似散布式聚集"( http://www.eaipatterns.com/BroadcastAggregate.html )模式,不是吗?

What you are looking for is something like a Scatter-Gather (http://www.eaipatterns.com/BroadcastAggregate.html) pattern, isn’t it?

您不知道受扇出影响的消费者,因此您可以:

You don’t know the consumers bound to the fan-out, so you can:

  1. 使用例如绑定生产者的队列来实现对消费者的保持活动. 每个消费者每秒发送一次保持活动状态,如果您没有收到消息,则可以认为该消费者处于脱机状态.
  2. 使用内存数据库在其中注册了使用者(始终保持活动状态).
  3. 使用 HTTP API 通过这种方式了解绑定到扇出的消费者列表:
  1. implement an keep-alive from the consumer(s) using for example an queue where the producer is bound. Each consumer sends a keep-alive each one second, if you don’t receive a message you can considerer the consumer off-line.
  2. Use an in-memory database where the consumer are registered (always with a keep-alive).
  3. Use the HTTP API to know the consumers list bound to the fan-out, in this way:

http://rabbitmqip/vhost/yourfanout/bindings/source,结果是这样的:

 [{"source":"yourfanout","vhost":"/","destination":"amq.gen-xOpYc8m10Qy1s4KCNFCgFw","destination_type":"queue","routing_key":"","arguments":{},"properties_key":"~"},{"source":" yourfanout","vhost":"/","destination":"myqueue","destination_type":"queue","routing_key":"","arguments":{},"properties_key":"~"}]

一旦计数了消费者,您就会知道答复计数.

Once count the consumers you know the replies count.

在发送请求之前调用API.

Call the API before send a request.

注意,仅当您使用绑定到使用者的临时队列时,最后一个才可以使用.

NOTE the last-one can works only if you use a temporary queue bound to the consumers.

我发现此资源可以为您提供帮助( http://geekswithblogs .net/michaelstephenson/archive/2012/08/06/150373.aspx )

I found this resource that could help you (http://geekswithblogs.net/michaelstephenson/archive/2012/08/06/150373.aspx)

我不确定您的最终范围,但是通过保持活动状态,您最多可以等待一秒钟,然后再确定消费者是否还活着.

I don't know exactly your final scope, but with a keep-alive you can wait max one second before decide if the consumer is alive.

这篇关于在扇出交换上等待所有rabbitmq响应吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆