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

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

问题描述

下面是该队列的理想设计:

Below is the desirable design of the queue with:

  • P生产者.插入数据的应用程序
  • X交流.
  • C1-C3消费者.从队列读取的应用程序
  • P producer. The application that insert data
  • X exchange.
  • C1-C3 consumer. The applications that read from the queue

队列详细信息:

  • 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?

如果答案是肯定的,那么您应该使用扇出.如果答案是否定的,那么您应该使用直接或主题.直接或主题的全部要点是,队列本身将仅基于将路由密钥与绑定密钥匹配而接收消息.

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.应当设置为non autodelete并且可能是持久的.如果您使用的是持久队列,那么您可能希望拥有持久消息(不要担心,如果队列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具有黑色的绑定键和白色的绑定键. 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天全站免登陆