RabbitMQ AMQP 队列设计 [英] RabbitMQ AMQP queue design

查看:39
本文介绍了RabbitMQ AMQP 队列设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是队列的理想设计:

Below is the desirable design of the queue with:

  • P 制作人.插入数据的应用程序
  • X 交换.
  • C1-C3 消费者.从队列中读取的应用程序

队列详情:

  • A.就像队列日志一样,如果没有客户端绑定,则消息将被丢弃.
  • B.这是一个工作队列.如果有条件匹配,它会做一些事情.
  • C.也是一个工作队列.它将转换数据

A 是可选的,但 B.C. 将始终在队列中,直到某个客户端进程连接它.

A is optional, but B. C. will always in queue until some client process connect it.

问题是确定我应该使用哪种类型的交换.它是扇出、直接还是主题?因为我希望 A 队列在没有连接客户端但 B & 的情况下丢弃消息C 应始终保留该消息.

The problem is determine which type of exchange that i should use. is it a fanout, direct or topic ? because I wanted the A queue to discard the message if there is no client connected but B & C should always keep the message.

生产者应该向交易所写入一次,还是使用不同的路由键或主题多次写入?

And should the producer write once to the exchange, or write multiple time with different routing key or topic ?

推荐答案

回答问题:我是否希望所有队列都接收所有消息?

Answer the question: Do I want all queues to receive all messages?

如果答案是肯定的,那么您应该使用扇出.如果答案是否定的,那么您应该使用直接或主题.direct 或 topic 的全部意义在于队列本身只会接收基于路由键与绑定键匹配的消息.

If the answer is yes then you should use fanout. If the answer is no then you should use direct or topic. The whole point of direct or topic is that the queues themselves will only receive messages based on matching the routing key to the binding key.

队列 A 应该由消费者 C1 实例化,并设置为自动删除和非持久性.这样当 C1 断开连接时,队列将被删除,消息将被丢弃.

Queue A should be instantiated by the consumer C1, and set to autodelete and non durable. This way when C1 disconnects the queue will be deleted and the messages will be discarded.

相反,队列 B 和 C 应该在交换时被实例化,无论是单独的,还是由生产者进行的.应该设置为非自动删除并且可能是持久的.如果您使用的是持久队列,您可能希望拥有持久消息(如果队列 A 不存在,请不要担心,即使持久消息在这里也不会成为问题).这样,一旦生产者开始发送消息,队列就会开始排队,不会丢失任何消息,即使消费者尚未运行.

Conversely Queues B and C should be instantiated when the exchange is, either separately, or by the producer. The should be set to non autodelete and probably durable. If you are using durable queues you might want to have persistent messages (don't worry if queue A doesn't exist even persistent message won't be a problem here). This way as soon as the producer starts sending messages the queues will start queuing them up and no message will be missed, even if the consumers are not yet running.

是否使用直接或主题交流是个人喜好.我知道直接交换应该更快,而主题交换允许路由/绑定键有很大的灵活性.

Whether to use direct or topic exchanges is personal preference. I understand that direct exchanges should be faster while topic exchanges allow a lot of flexibility with routing/binding keys.

我不是 100% 你最后一个问题的意思.每条消息只能写入一次交换.如果使用扇出,交换将负责正确地将消息路由到队列,就是这样.如果您使用的是直接交换或主题交换,那么它可以通过绑定键来确保每个队列都接收到正确的消息.您不需要发送带有多个路由键的消息,如果您希望做类似的事情,那么您的理解就会倒退.但是你可以从一个队列中拥有多个绑定键到交换.

I am not 100% what you mean by your last question. Each message should only be written once to an exchange. If using fanout the exchange will take care of routing the messages to the queues correctly and that is it. If you are using direct or topic exchanges then its down to the binding keys to make sure that each queue receives the correct messages. You should not need to send a message with more than one routing key, if you are wishing to do something like that then you have got something backwards in your understanding. But you can have multiple binding keys to the exchange from a single queue.

简单的例子.X 是直接交换.B有黑色装订键,C有1个黑色装订键和1个白色装订键.P 发送带有黑色或白色路由键的消息.如果是黑色则 B 和 C 都会收到消息,如果是白色则只有 C 会收到.

Simple example. X is a direct exchange. B has the binding key black, C has one binding key of black and one binding key of white. P sends messages with either the routing key black or white. If it is black then both B and C will receive the message, if it is white then only C will receive it.

这篇关于RabbitMQ AMQP 队列设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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