Basic introduction to rabbitMQ (learning summary)

basic concept

1. In most applications, message service middleware can be used to improve system asynchronous communication and expand decoupling capabilities

2. Two important concepts in message service:

Message broker (message broker) and destination (destination) When the message sender sends a message, it will be taken over by the message broker, and the message broker ensures that the message is delivered to the designated destination.

3. The message queue mainly has two forms of destinations

1. Queue (queue): point-to-point message communication (point-to-point)

2. Topic: publish/subscribe message communication

4. Point-to-point:

  • The message sender sends a message, the message agent puts it into a queue, the message receiver gets the message content from the queue, and the message is removed from the queue after reading
  • The message has only one sender and receiver, but it does not mean that there can only be one receiver

5. Publish and subscribe:

  • The sender (publisher) sends a message to the topic, and multiple receivers (subscribers) listen (subscribe) to the topic, then they will receive the message at the same time when the message arrives

6. JMS (Java Message Service) JAVA message service:

  • Specification based on JVM message broker. ActiveMQ and HornetMQ are JMS implementations

7. AMQP(Advanced Message Queuing Protocol)

  • Advanced message queuing protocol, also a message broker specification, compatible with JMS
  • RabbitMQ is an implementation of AMQP

8. Spring support

  • spring-jms provides support for JMS
  • spring-rabbit provides support for AMQP
  • An implementation of ConnectionFactory is required to connect to the message broker
  • Provide JmsTemplate, RabbitTemplate to send messages
  • @JmsListener (JMS), @RabbitListener (AMQP) annotations listen to messages published by the message broker on the method
  • @EnableJms, @EnableRabbit enable support

9. Spring Boot auto-configuration

  • JmsAutoConfiguration
  • RabbitAutoConfiguration

10. MQ products on the market

  • ActiveMQ、RabbitMQ、RocketMQ、Kafka

 

Introduction to RabbitMQ:

RabbitMQ is an open source implementation of AMQP (Advanved Message Queue Protocol) developed by erlang.

Core idea

Message

Message, the message is anonymous, it consists of message header and message body. The message body is opaque, while the message header consists of a series of optional attributes, including routing-key (routing key), priority (priority relative to other messages), delivery-mode (indicating that the message may require persistent storage), etc.

Publisher

A producer of messages is also a client application that publishes messages to an exchange.

Exchange

An exchange that receives messages from producers and routes them to queues in the server.

There are 4 types of Exchange: direct (default), fanout, topic, and headers. Different types of Exchange have different strategies for forwarding messages

Queue

A message queue, used to store messages until sent to consumers. It is the container of the message and the destination of the message. A message can be put on one or more queues. The message is always in the queue, waiting for the consumer to connect to the queue to take it away.

Binding

Bindings are used for associations between message queues and exchanges. A binding is a routing rule that connects an exchange and a message queue based on a routing key, so an exchange can be understood as a routing table composed of bindings.

The binding of Exchange and Queue can be a many-to-many relationship.

Connection

A network connection, such as a TCP connection.

Channel (long connection)

Channel, an independent bidirectional data stream channel in a multiplexed connection. A channel is a virtual connection established in a real TCP connection. AMQP commands are sent through the channel. Whether it is publishing a message, subscribing to a queue or receiving a message, these actions are all completed through the channel. Because it is very expensive for the operating system to establish and destroy TCP, the concept of channel is introduced to reuse a TCP connection.

Consumer

The consumer of the message represents a client application program that obtains messages from the message queue.

Virtual Host

A virtual host, representing a collection of exchanges, message queues, and related objects. Virtual hosts are separate domains of servers that share the same authentication and encryption environment. Each vhost is essentially a mini version of RabbitMQ server, with its own queue, switch, binding and permission mechanism. The vhost is the basis of the AMQP concept and must be specified when connecting. The default vhost of RabbitMQ is /.

Broker

Represents the message queue server entity

 

Guess you like

Origin blog.csdn.net/wzw_wwl/article/details/130987368