Message queue middleware - Docker installs RabbitMQ, AMQP protocol, and main roles

overview

Whether it is a microservice or a distributed system architecture, message queuing middleware is an indispensable and important link. The mainstream message queuing middleware includes RabbitMQ, RocketMQ, etc. From this article, we will introduce the messages represented by RabbitMQ in detail. Queue middleware.

AMQP protocol

AMQP.png

  • The AMQP protocol is an application layer standard protocol that provides unified messaging services. The client and message middleware based on this protocol can transmit messages, and it is not limited by different client/middleware products and different development languages.
  • The AMQP protocol is a binary protocol that provides asynchronous, safe, and efficient interaction between client applications and message middleware.
  • AMQP, as a middle-tier service, separates message production and consumption. When the consumer generates an exception, it does not affect the consumer's consumption of the message. When the consumer is abnormal, the message produced by the producer can be stored in the memory of the service or The disk will not affect the rate of consumption. At the same time, the message can also be delivered to the specified consumer for consumption based on the routing rules.

Important role of AMQP protocol

1. Producers and Consumers

  • The producer is the subject of producing messages, and the consumer is the subject of consuming messages
  • Data integration and system decoupling, asynchronous processing and event-driven, traffic Xuefeng, eventual consistency of transaction messages and distributed transactions
  • The producer produces a message and throws it to the message broker, and the message broker passes the message to the consumer according to the delivery rules

2. Switch

  • A switch is like a router for a message broker. After getting a message, it routes it to one or zero queues according to certain rules (routing keys). The switch has multiple routing modes.
  • Based on the message producer and routing rules, the message can be delivered to the specified Message Queue. The switch receives the message delivered by the producer, and based on the routing rule and queue binding relationship, it matches the delivery corresponding switch or queue for distribution. The switch does not store the message. just retweet

Switch type:

  • Directly connected to the switch: deliver to the corresponding queue according to the exact match of the routing key
  • Fan-shaped switch: Regardless of the routing key, the message is copied and routed to all queues bound to it, providing a broadcast effect.
  • Topic switch: deliver to the corresponding queue according to the routing key according to the pattern matching
  • The switch also has its own attributes, you can define your own name, whether it is persistent or not, and other options.

3. Queue

  • The queue is a temporary storage place for messages. If at least one consumer subscribes to the queue, the message will be sent to these subscribed consumers immediately. However, if the message reaches an unmanned subscription queue, the message will wait in the queue. Consumers then distribute.
  • There is a binding relationship between Exchange and Message Queue. After the message arrives at Exchange, the message can be delivered to the bound Message Queue based on the routing policy based on the routing policy.
  • Message queues store messages in memory or disk, and forward these messages to one or more consumers in a certain order. Each message queue is independently isolated and does not affect each other.
  • Message queues have different attributes (private, shared, persistent, temporary, client-defined or server-defined, etc.), and the corresponding type can be selected based on actual needs

4. Message

  • The message is the carrier of information and an entity of the AMQP protocol. The message consists of two parts
  • Payload: the real information, any content you want to transmit, this part of the content is transparent to the message broker
  • Meta information: including message attributes such as routing key, content type, encoding, and persistence, etc., which will be parsed by the message agent. The message agent will deliver and store the message according to the message attributes. This part is related by the message agent. And consumers don't care about it.

5. Channel

  • The network channel is a lightweight link built on the Connection link. Almost all operations are carried out in the Channel. The Channel is a channel for reading and writing messages. The client can establish a link to each Channel, and each Channel represents A session task.
  • Any number of Channels can be created on a Connection

Docker install RabbitMQ

1. View the RabbitMQ image in the Docker warehouse

# 查询镜像
docker search rabbitmq

# 下载镜像
docker pull rabbitmq

2. Start MQ installation management

If deploying on cloud services, you need to open the following ports in the security group: 15672 (UI page communication port), 5672 (client port), 25672 (internal communication port between servers), 61613 (stomp message transmission), 1883 (MQTT message queue telemetry transmission).

docker run -d --name rabbit -e \
RABBITMQ_DEFAULT_USER=stark -e RABBITMQ_DEFAULT_PASS=1990@stark 
-p 15672:15672 \
-p 5672:5672 \
-p 25672:25672 \
-p 61613:61613 \
-p 1883:1883 rabbitmq:management

Using http://127.0.0.1:15672access, account number and password are the values ​​of parameters RABBITMQ_DEFAULT_USERand RABBITMQ_DEFAULT_PASSsettings.

rabbitmq.png

Guess you like

Origin blog.csdn.net/xuezhiwu001/article/details/130532535