This is the 14th day of my participation in the August More Text Challenge. For details, see: August More Text Challenge

RabbitMQ is a common message queue, and this part of the interview questions has been sorted out.

The role of message queues

Peak shifting and valley filling, asynchronous, decoupled

The reason for rabbitMQ high performance

Erlang, developed by Ericsson, is a programming language developed specifically for switch software development

Erlang characteristics

  • A general purpose concurrency – oriented programming language suitable for distributed systems
  • Based on the vm interpretation, cross-platform deployment
  • Interprocess context switching is much more efficient than C
  • Has the same latency as the native Socket

conclusion

  • RabbitMQ is implemented using Erlang, which is inherently high performance
  • RabbitMQ has a wide range of applications in both the Internet and finance
  • Context switching between Processes in Erlang is much more efficient than in C and Java, further improving RabbitMQ’s concurrency performance
  • Erlang’s network performance has the same latency as native sockets, making RabbitMQ’s network IO performance extremely high

The rabbitmq architecture

Closer agreement

Exchange summary

  • The AMQP protocol directly determines the internal structure and external behavior of RabbitMQ
  • For the sender, send the message to a specific Exchange
  • After the message passes through the Exchange route, it reaches the specific queue
  • The consumer takes the message off the listening queue
  • There are three main types of Exchange: Direct, Topic, and Fanout
  • Direct: Routing Key = Binding Key, which is easy to configure and use
  • Fanout (broadcast route) : Sends all the bound queues in a group, applicable to message broadcast
  • Topic routing: More complex, but can be downgraded to Direct. It is recommended to use it first to allow for further expansion

What are the scenarios for using RabbitMQ?

  • Panic buying, peak chipping and valley filling to prevent system collapse.
  • Delay the processing of information, such as sending an email notification after 10 minutes to users who have placed an order but have not paid.
  • Decoupling system, regarding the new function can be individually write module extensions, such as the user to confirm after evaluation, added to the user to return integral function, this time don’t have to add new integral function in a business code, only need to put the new integral interface to subscribe to a message queue can confirm evaluation, the back to add any function you just need to subscribe to the corresponding message queue.

What are the important roles in RabbitMQ?

The important roles in RabbitMQ are producer, consumer, and agent:

  • Producer: Message creator who is responsible for creating and pushing data to the message server;
  • Consumer: The receiver of the message, used to process the data and acknowledge the message;
  • Agent: This is RabbitMQ itself, used to act as a “Courier”. It does not produce messages itself, but acts as a “Courier”.

What are the important components of RabbitMQ?

  • ConnectionFactory: A manager used in program code to establish a connection between an application and Rabbit.
  • Channel: the Channel through which messages are pushed.
  • Exchange: Used to receive and distribute messages.
  • Queue: Used to store messages from producers.
  • RoutingKey: Used to assign the generator’s data to the switch.
  • BindingKey: Used to bind an exchange message to a queue.

What is the role of vhost in RabbitMQ?

Vhosts: Each RabbitMQ can create a number of Vhosts, which we call virtual hosts. Each virtual host is a mini version of RabbitMQ, with its own queues, switches, and bindings, and has its own permissions.

How are RabbitMQ messages sent?

The client must first connect to the RabbitMQ server to publish and consume messages. A TCP connection is created between the client and the RabbitMQ server. Once TCP is open and authenticated (authentication is the user name and password you send to the RabbitMQ server), Your client creates an AMQP channel with RabbitMQ. A channel is a virtual connection created over “real” TCP. Amqp commands are sent over the channel and each channel has a unique ID. Subscription queues are all done through this channel.

How does RabbitMQ ensure message stability?

  • Provides transactional capabilities.
  • By setting the channel to confirm mode.

How to avoid message loss in RabbitMQ?

  • Persisting messages to the disk ensures that server restart messages are not lost.
  • Each cluster has at least one physical disk to ensure that messages fall on the disk.

What are the conditions for successful message persistence?

  • Declared queues must be durable as true.
  • Message push deliveryMode must be set to persistent and deliveryMode to 2 (persistent).
  • The message has arrived at the persistence exchange.
  • The message has arrived on the persistent queue.

The above four conditions are met to ensure successful message persistence.

What are the disadvantages of RabbitMQ persistence?

The downside of persistence is that it reduces the throughput of the server by using disk rather than memory storage. Use SSDS whenever possible to mitigate throughput issues.

How many broadcast types are there in RabbitMQ?

  • Direct (default) : The most basic and simple mode in which the sender sends messages to subscribers. If there are multiple subscribers, the message is sent in a polling mode by default.
  • Headers: Similar to direct, but with poor performance, this type is rarely used.
  • Fanout: Distribution model that distributes consumption to all subscribers.
  • Topic: Matches the subscription pattern, using the regex to match the message queue. Whatever matches can be received.

How does RabbitMQ implement delayed message queuing?

There are two ways to implement a delay queue:

  • Through the expiration of the message into the dead letter exchange, and then forwarded by the exchange to the delay consumption queue, to achieve the delay function;
  • Use the Rabbitmq-delayed – message-Exchange plug-in to implement the delay function.

What is a RabbitMQ cluster for?

Clusters serve two main purposes:

  • High availability: If a server fails, RabbitMQ can still be used.
  • High capacity: The cluster can hold more message volumes.

What are the types of RabbitMQ nodes?

  • Disk node: Messages are stored on disk.
  • Memory node: Messages are stored in memory. When the server restarts, messages are lost. The performance is higher than that of disk type.

What issues should be addressed when setting up a RabbitMQ cluster?

  • Nodes are connected by “–link”. This attribute cannot be ignored.
  • The Erlang cookie value used by each node must be the same. This value is equivalent to the “secret key” function and is used for authentication of each node.
  • The entire cluster must contain one disk node.

Is each RabbitMQ node a full copy of the others? Why is that?

No, for two reasons:

  • Storage space considerations: If each node has a full copy of all queues, the new node will not only add more storage space, but also add more redundant data;
  • Performance considerations: If every message needs to be copied to every node in the cluster, then the new node will not improve the ability to process messages and will at best maintain the same or worse performance as a single node.

What happens when a single disk node in a RabbitMQ cluster crashes?

If the disk node of the only disk crashes, the following operations cannot be performed:

  • Cannot create queue
  • Cannot create switch
  • Cannot create binding
  • Cannot add user
  • Cannot change permissions
  • You cannot add or delete cluster nodes

The only disk node crashes, the cluster is still running, but you can’t change anything.

Does RabbitMQ require cluster nodes to stop in order?

RabbitMQ stops the cluster in the correct order, stopping the memory nodes first and then the disk nodes last. If the order is reversed, messages may be lost.