Message queues are also called Message Queues (MQ). RabbitMQ is an excellent and open source platform for message queuing and is used by many companies. RabbitMQ server is written in the Erlang language and based on AMQP. This article gives you a summary of 29 RabbitMQ questions.

1. What is RabbitMQ?

RabbitMQ is open source message broker software (also known as message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). RabbitMQ servers are written in the Erlang language, while clustering and failover are built on top of the open telecom platform framework. All major programming languages have client libraries that communicate with proxy interfaces.

2. The RabbitMQ characteristics?

Reliability: RabbitMQ uses mechanisms to ensure reliability such as persistence, transport confirmation, and publication confirmation.

Flexible routing: Messages are routed through the exchange before they are queued. For typical routing, RabbitMQ already provides some built-in switches. For more complex routing functions, multiple switches can be bound together, or you can implement your own switch through a plug-in mechanism.

Scalability: Multiple RabbitMQ nodes can form a cluster or dynamically expand the cluster based on service requirements.

High availability: Queues can be mirrored on machines in the cluster, making them available even if some nodes fail.

Multiple protocols: RabbitMQ supports multiple messaging middleware protocols, including STOMP and MQTT, in addition to AMQP natively.

Multi-language clients :RabbitMQ supports almost all common languages, such as Java, Python, Ruby, PHP, C#, JavaScript, etc.

Administration Interface: RabbitMQ provides an easy-to-use user interface that allows users to monitor and manage messages, nodes in a cluster, etc.

Plugin mechanism: RabbitMQ provides many plugins to extend in many ways, but you can also write your own.

3. What is AMQP?

RabbitMQ is an implementation of Erlang for AMQP (RabbitMQ also supports STOMP2, MQTT3, etc.). The AMQP model is the same as RabbitMQ. The producer sends a message to the exchange. The switch is bound to the queue.

Switches, switch types, queues, bindings, routing keys, and so on in RabbitMQ are all concepts associated with the AMQP protocol. The latest version of RabbitMQ supports AMQP 0-9-1 by default.

4.AMQP protocol Layer 3?

Module Layer: The highest Layer of the protocol, which defines the commands that the client invokes to implement its own business logic.

Session Layer: The middle Layer, which is responsible for sending client commands to the server and sending server responses back to the client, providing reliability synchronization and error handling.

TransportLayer: The lowest layer, which transmits binary data streams and provides frame processing, channel feeding, error detection, and data representation.

5. What are the components of the AMQP model?

  • Exchange: Component of a message broker server that routes messages to queues.
  • Queue: Data structure used to store messages, located on hard disk or in memory.
  • Binding: A set of rules that tells the exchange to which queue messages should be delivered.

6. Are they all producers?

The message producer is the party that delivers the message.

A message generally contains two parts: payload and Label.

7.消费者Consumer?

Consuming messages, that is, the party that receives the message.

The consumer connects to the RabbitMQ server and subscribes to the queue. Consume only the body of the message and discard the label.

Broker service node?

The Broker can be seen as a service node to RabbitMQ. Generally, the next Broker can be regarded as a RabbitMQ server.

9. The Queue Queue?

Queue:RabbitMQ’s internal object for storing messages. Multiple consumers can subscribe to the same queue, in which case messages in the queue are amortized (polled) for processing by multiple consumers.

10.Exchange?

Exchange: Producers send messages to exchanges, which route messages to one or more queues. When the route is unavailable, it is either returned to the producer or discarded.

11.RoutingKey?

When a producer sends a message to an exchange, it specifies a RoutingKey that specifies the routing rules for the message. This RoutingKey needs to be used in conjunction with the exchange type and the BindingKey to take effect.

12. The Binding Binding?

To bind the switch to the queue, usually a BindingKey is specified so RabbitMq knows how to route messages to the queue correctly.

13. Are there four types of switches?

There are four main types.

Fanout: Routes all messages sent to the switch to all queues bound to the switch.

Direct: Routes messages to queues where BindingKey and RoutingKey exactly match.

topic:

Matching rules:

A RoutingKey is a dot ‘.’: delimited string. For example, Java. Xiaoka. Show

BindingKey, like a RoutingKey, is a dot delimited string.

BindingKey can use * and # for fuzzy matching, * to match one word, and # to match multiple or zero words

Headers: Routing messages that do not rely on routing keys to match rules. Is matched based on the HEADERS attribute in the content of the sent message. Poor performance, basic use.

14. Producer message running?

1.Producer first connects to the Broker, establishes a Connection, and starts a Channel.

2.Producer declares a switch and sets its properties.

3.Producer declares a queue and sets its properties.

4.Producer binds switches to queues using routing keys.

5.Producer sends messages to the Broker containing routing keys, switches, and other information.

6. The switch searches for the matching queue based on the received routing key.

7. If yes, the message is stored in the corresponding queue. If no, the message is discarded or returned to the producer based on the producer’s configuration.

8. Close the channel.

9. Manage connections.

15. Consumer receiving message process?

1.Producer first connects to the Broker, establishes a Connection, and starts a Channel.

2. Messages in the queue that request the Broker to consume the response may set the callback function for the response.

3. Wait for the Broker to respond, deliver the message in the queue, and receive the message.

4. The consumer acknowledges the received message, ACK.

5.RabbitMq deletes confirmed messages from the queue.

6. Close the channel.

7. Close the connection.

16. What can be done when a switch fails to find a matching queue based on its own type and routing key?

Mandatory: true Returns a message to the producer.

Mandatory: false Indicates that the value is directly discarded.

17. Dead letter queue?

DLX is a dead-letter-exchange. When a message becomes dead message in one queue, it can be re-sent to another exchange, the DLX. Queues bound to DLX are called dead letter queues.

18. What are the causes of dead letters?

  • The message was rejected (basic. Reject/basic. Nack) and Requeue = false.
  • The message TTL expired.
  • The queue was full and could not be added.

19. Delay queue?

Store the corresponding delayed message, which means that after the message is sent, the consumer does not want to receive the message immediately, but wait a certain time before the consumer can receive the message for consumption.

20. Priority queue?

Queues with higher priority are consumed first.

This can be done with the x-max-priority parameter.

Priorities are meaningless when consumption is faster than production and brokers are not piling up.

21. Transaction mechanism?

There are three methods associated with the transaction mechanism in the RabbitMQ client:

Channel.txselect is used to set the current channel to transaction mode.

Channel.txcommit is used to commit transactions.

Channel.txrollback is used to roll back the transaction if an exception is thrown before the transaction is committed due to a RabbitMQ crash or for other reasons.

22. Send confirmation mechanism?

The producer sets the channel to confirm mode, which assigns a unique ID to all messages sent over another channel. Once the message has been sent to all matching queues RabbitMQ will send a basic.ack to the producer (containing the unique ID of the message). This way the producer knows that the message has arrived at the corresponding destination.

23. How do consumers get information?

  • push

  • la

24. How to reject a message that a consumer cannot process for some reason?

  • channel .basicNack
  • channel .basicReject

25. Message transfer Guarantee hierarchy?

At most once. Messages can be lost, but not repeated.

-Leonard: At least once. Messages are not lost, but may be transmitted repeatedly.

-Blair: Every message must be transmitted Exactly once.

26.vhost?

Each RabbitMQ server can create a virtual message server, also called a virtual host, or vhost for short.

The default value is /.

27. Node types in the cluster?

Memory node: RAM, which writes changes to memory.

Disk node: disc, disk write operation.

RabbitMQ requires at least one disk node.

28. Queue structure?

Usually consists of the following two parts?

Rabbit_amqqueue_process: handles protocol-related messages, such as receiving messages from producers, delivering messages to consumers, and processing confirmation messages (including confirms on the production end and ACK on the consumer end).

Backing_queue: Is the concrete form and engine of the message store and provides the associated interface to the Rabbit amqqueue process to invoke.

29. How many states can messages have in RabbitMQ?

Alpha: Message content (including message body, attribute, and HEADERS) and message index are stored in memory.

Beta: Message content is kept on disk and message indexes are kept in memory.

Gamma: The message content is stored on disk, and the message index is both on disk and in memory.

Delta: The message content and index are on disk.

Reference:

RabbitMQ Field Guide

Inside RabbitMQ

Baidu encyclopedia