Administrator
发布于 2023-10-13 / 59 阅读
0
0

1012ReThinkRabbitMq

基础概念

exchange的作用是:

An exchange is a very simple thing. 

On one side it receives messages from producers and on the other side it pushes them to queues. 

The exchange must know exactly what to do with a message it receives.

Should it be appended to a particular queue? Should it be appended to many queues? Or should it get discarded.
There are a few exchange types available: direct, topic, headers and fanout

binding的作用是:

That relationship between exchange and a queue is called a binding.
by binding,the rabbitmq knows , the exchange should send messages to where? queue1 ? queue2 ? or queue3?

routing key 和 binding key的区别:

routing key是message的属性,而binding key describe the relationship of exchange and queue.

if routing key of A message matches bingding key, the A message will appended to the queue

image-20231012185445140


Subscriber 和 Queue的关系

image-20240218154103045

2种消费模型

2种消费模型:

  • 5条消息,C1 消费2条,C2消费3条
  • 5条消息,C1 消费了5条,C2 也消费了5条

如果想实现第2种消费模型,那么C1 和 C2需要分别创建一个queue,这样,就每个consumer消费各自的queue中的消息。

如果想实现第1种消费模型,即共享订阅,即Shared Subscription Available

由于mqtt协议要求客户端唯一(即clientId唯一),导致每一个client都会创建该clientId对应的queue,因此在3.1.1版本下,是无法实现共享订阅的。参考:

https://blog.csdn.net/qq_41034780/article/details/129087592

幸运的是,在MQTT V5,支持了共享订阅,这样就能实现第1种消费模型。

参考:https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901080

https://blog.rabbitmq.com/posts/2023/07/mqtt5/#feature-15-optional-server-feature-availability


评论