RabbitMQ 循环法
RabbitMQ Round Robin
我正在尝试构建一个系统,其中主服务创建一堆消息并根据路由键将它们路由到正确的队列。我有那个工作,消息正在 worker/slave 端被消耗。但是我希望工作人员只从队列中获取一条消息,而不是将所有 15 条消息放入队列中。
我正在看这个 https://github.com/streadway/amqp/blob/master/channel.go#L616 但是我不确定如何设置它所以只拍摄了一个事件。
有什么想法吗?
免责声明:我没有使用过 Go AMQP 客户端,但 AMQP 协议语义应该在客户端实现中通用,所以我会试一试。
您已经正确地将 prefetch-size
和 prefetch-count
参数识别为要调整的配置变量。 RabbitMQ documentation 在这方面说如下:1
AMQP specifies the basic.qos
method to allow you to limit the number of unacknowledged messages on a channel (or connection) when consuming (aka "prefetch count").
如果您希望每个消费者一次只发送一条消息,您应该将 prefetch-count
设置为 1,并保留 prefetch-size
未定义(即 0):
err := channel.Qos(1, 0, false)
if err != nil {
// ...
}
1
在 RabbitMQ's AMQP reference 中还有关于此的更长描述:
long prefetch-size
The client can request that messages be sent in advance so that when the client finishes processing a message, the following message is already held locally, rather than needing to be sent down the channel. [...] The server will send a message in advance if it is equal to or smaller in size than the available prefetch size (and also falls into other prefetch limits). May be set to zero, meaning "no specific limit", although other prefetch limits may still apply. The prefetch-size is ignored if the no-ack option is set.
[...]
short prefetch-count
Specifies a prefetch window in terms of whole messages. This field may be used in combination with the prefetch-size field; a message will only be sent in advance if both prefetch windows (and those at the channel and connection level) allow it. [...]
我正在尝试构建一个系统,其中主服务创建一堆消息并根据路由键将它们路由到正确的队列。我有那个工作,消息正在 worker/slave 端被消耗。但是我希望工作人员只从队列中获取一条消息,而不是将所有 15 条消息放入队列中。
我正在看这个 https://github.com/streadway/amqp/blob/master/channel.go#L616 但是我不确定如何设置它所以只拍摄了一个事件。
有什么想法吗?
免责声明:我没有使用过 Go AMQP 客户端,但 AMQP 协议语义应该在客户端实现中通用,所以我会试一试。
您已经正确地将 prefetch-size
和 prefetch-count
参数识别为要调整的配置变量。 RabbitMQ documentation 在这方面说如下:1
AMQP specifies the
basic.qos
method to allow you to limit the number of unacknowledged messages on a channel (or connection) when consuming (aka "prefetch count").
如果您希望每个消费者一次只发送一条消息,您应该将 prefetch-count
设置为 1,并保留 prefetch-size
未定义(即 0):
err := channel.Qos(1, 0, false)
if err != nil {
// ...
}
1 在 RabbitMQ's AMQP reference 中还有关于此的更长描述:
long prefetch-size
The client can request that messages be sent in advance so that when the client finishes processing a message, the following message is already held locally, rather than needing to be sent down the channel. [...] The server will send a message in advance if it is equal to or smaller in size than the available prefetch size (and also falls into other prefetch limits). May be set to zero, meaning "no specific limit", although other prefetch limits may still apply. The prefetch-size is ignored if the no-ack option is set.
[...]
short prefetch-count
Specifies a prefetch window in terms of whole messages. This field may be used in combination with the prefetch-size field; a message will only be sent in advance if both prefetch windows (and those at the channel and connection level) allow it. [...]