Spring boot integration rabbitmq example tutorial

1、 Introduction to rabbitmq

Rabbitmq is a kind of message middleware, which is the basic software to send and receive messages in distributed systems There are many of these software, including ActiveMQ (from APACHE), rocketmq (from Alibaba, which has been transferred to Apache)

The working process of message middleware can be represented by producer consumer model That is, producers constantly send information to the message queue, while consumers consume information from the message queue The specific process is as follows:

As can be seen from the above figure, producer, message queue and consumer are the three most important concepts for message queue. The producer sends messages to the message queue, and the consumer listens to the specified message queue. After the message queue receives the message, it receives the message from the message queue and gives corresponding processing Message queuing is often used to transfer information between distributed systems

For rabbitmq, in addition to these three basic modules, a module, exchange, is added The producer sends the message to the switch, and the switch forwards the corresponding message to the corresponding message queue according to the scheduling policy The workflow of rabitmq is as follows:

Then I'll talk about the switch The main function of the switch is to receive the corresponding message and bind it to the specified queue There are four types of switches: direct, topic, headers and fanout

Direct is the default switch mode of rabbitmq and the simplest mode That is, when creating a message queue, specify a bindingkey When the sender sends a message, specify the corresponding key When the key is consistent with the bindingkey of the message queue, the message will be sent to the message queue

Topic forwarding information is mainly based on wildcards, and the binding between queue and switch is mainly based on a pattern (wildcard + string). When sending a message, the message will be sent to the message queue only when the specified key matches the pattern

Headers are also matched according to a rule. A set of key value pair rules will be specified when the message queue is bound to the switch, and a set of key value pair rules will be specified when sending messages. When the two sets of key value pair rules match, the messages will be sent to the matching message queue

Fanout is in the form of routing broadcast. It will send messages to all queues bound to it. Even if the key is set, it will be ignored

Concept:

pattern:

1、direct

Direct connection mode is used for task distribution between instances

2、topic

Topic mode, which is distributed to the queue bound to the exchange through configurable rules

3、headers

For complex distribution of rules, use the parameters in headers to express the rules

4、fanout

Distribute to all queues bound to the exchange, ignoring the routing key

install

The installation of stand-alone version is very simple. The general steps are as follows:

For cluster installation, please refer to this article:

Rabbitmq cluster installation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>