Frequently Asked RabbitMQ Interview Questions and Answers
by Sachin, on Jul 4, 2022 8:35:50 PM
Q1. What is RabbitMQ ?
Ans
RabbitMQ is an open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP). The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover.
Q2. Why RabbitMQ?
Ans
- except Qpid, RabbitMQ Is the only one that has achieved AMQP Standard message server
- reliability, RabbitMQ Persistence support for, It ensures the stability of the message
- High concurrency, RabbitMQ Used Erlang development language, Erlang It's a language developed for telephone switches, Born with a high and luminous ring, And high availability features
- Cluster deployment is simple, It should be Erlang bring RabbitMQ Cluster deployment becomes super simple
- High community activity, According to the information on the Internet, RabbitMQ It's also the first choice
Q3. What are the characteristics of RabbitMQ ?
Ans
- reliable
RabbitMQ Use Such as persistence, Transmission confirmation and release confirmation mechanisms to ensure reliability
- Flexible routing
Routing messages through switches. For typical routing functions, RabbitMQ Some built-in switches have been provided to implement. For more complex routing functions, Multiple Switches are bound together, This needs to be implemented through plug-ins
- Extensibility
Multiple RabbitMQ Nodes can form a cluster, You can also dynamically expand the nodes in the cluster according to the actual business situation
- High availability
Queues can be mirrored on machines in the cluster, Make the queue available even if some nodes have problems
- There are many supported protocols
RabbitMQ Besides native support AMQP agreement, And support STOMP, MQTT And other message middleware protocols
- Multilingual client
RabbitMQ Support for almost any common language, such as GO, Java, Python, Ruby, PHP etc.
- WEB Management interface
RabbitMQ Provides an easy-to-use user interface, Enables users to monitor and manage messages, Nodes in the cluster, etc
- Command plug-in mechanism
RabbitMQ Many plug-ins are provided, To realize the extension from many aspects, Of course, you can also write your own plug-in
Q4. What is the Role of RabbitMQ?
Ans
- Peak shaving and valley filling
- Producer and consumer business decoupling
- Asynchronous communication between services
- Timing task
- Sequential consumption
Q5. What are the Six Modes of RabbitMQ?
Ans
- single
Simple producer production messages, Put in queue, Consumer consumption news
- work
When producers produce news faster than consumers consume, You have to think about it work Working mode, This can increase processing speed and load work Patterns and single Similar model, It's just work Model than single There are more consumers in the model
- publish
Application scenarios : The use of simple message queues , One producer one consumer
- routing
The message producer sends the message to the switch according to the routing judgment, The route is a string (info) Currently generated messages carry routing characters ( Object method ), Switches are routed according to key. Only the upper route can be matched key Corresponding message queue, The corresponding consumer can consume the news
- topic
Topic pattern, A message is obtained by multiple consumers, The goal of the message queue You can use BindingKey, Use wildcards
- rpc
Through remote procedure call
Q6. The Queue Structure of RabbitMQ?
Ans
- rabbit_amqqueue_process
Responsible for protocol related message processing. That is, receiving messages from producers. Delivering messages to consumers. Process message confirmation, etc
- backing_queue
It's the concrete form and engine of message storage. And to rabbit_amqqueue_process, it provides the relevant interface for calling
Q7. What is Exchange?
Ans
Messages is not posted directly in the queue, the user sends messages to the exchange, it is responsible for routing the messages to the queues. Exchange helps in receiving messages from the producer request and routes them by bindings and routings keys for messaging queues. It acts like a bindage, linking between an exchange and a queue.
Q8. What is a Server in RabbitMQ?
Ans
The RabbitMQ server is a robust and scalable implementation of an AMQP broker. Running RabbitMQ-server in the foreground displays a banner message, and reports on progress in the startup sequence, concluding with the message "broker running", indicating that the RabbitMQ broker has been started successfully.
Q9. What is rabbitmqadmin?
Ans
The rabbitmqadmin is a command-line tool that performs some of the same actions as the Web-based UI. It is shipped with the management plugin and provides a more convenient way for automating tasks. This command-line tool supports all versions of Python and can be downloaded after the management plugin is installed.
Q10. What is a RabbitMQ channel?
Ans
They enable you to have a single connection to the RabbiMQ server, but for different parts of your application they have sandboxed communication. Channels are how the RabbitMQ server communicates with your application. It hold one connection (instance) per client process and many channels in that process (instance)
Q11. What is Routing key in RabbitMQ?
Ans
The message structure in the RabbitMQ is divided into two parts. They are the payload and routing key.
The routing key is used to describe the payload passed by the system and the messaging system itself to determine who will be the receiver of the payload. The routing key also enables you to bind queues to exchanges to deliver the message to the queue based on the four types of exchanges.
Q12. What are all the client libraries supported by the RabbitMQ?
Ans
- RabbitMQ Java Client
- RabbitMQ JMS Client
- RabbitMQ .NET Client - supports .NET Core and .NET 4.5.1+
- RawRabbit - Higher-level client which targets ASP.NET vNext and .NET Core
- Bunny - RabbitMQ Ruby Client
- March Hare - JRuby RabbitMQ Client
- Pika & aio-pika - a pure Python Client
- Aio-amqp - an asynchronous Python Client
- Php-amqplib - Fully featured PHP RabbitMQ Client
- Amqp.node - RabbitMQ Client for Node JS
- Lapin & amiquip - RabbitMQ Client for rust
Q13. List the types of exchanges available in RabbitMQ?
Ans
Direct Exchanges - This type route the messages with a routing key equal to the routing key declared by the binding queue.
Fanout Exchanges - This type route the messages to all bound queues indiscriminately.
Topic Exchanges - This type route the messages to the queues if the routing key of the route is matched all or a portion of the matching patterns.
Headers Exchanges - This type route the messages based upon the matching of message headers to the expected headers which are specified in the binding queue.
Q14. List the design patterns used by the RabbitMQ?
Ans
One-Message-to-One-Consumer Model
This model is used to deliver each task to exactly one worker. The exchange types of this pattern are,
- Round-Robin - In this patter, the RabbitMQ dispatches each message to the next consumer in the sequence.
- Next Available Worker - In this type, the RabbitMQ won’t give more than one message to a worker at a time.
One-Message-to-Multiple-Consumers Model
In this model, one message is dispatched to multiple consumers. Some exchange types of this pattern are,
- Publish/Subscribe - In this patter, a producer sends a message to a set of subscribed consumers.
Q15. What is a dead letter queue in RabbitMQ?
Ans
In general, a death letter queue (DLQ), also referred to as an undelivered-message queue, is a holding queue of messages that can not be sent to their destinations for some reason.
In RabbitMQ, the dead letter queue is service implementation to store messages that satisfy one or more of the following failure criteria.
- Message that is sent to a queue that does not exist.
- Queue length limit exceeded.
- Message length limit exceeded.
- Message is rejected by another queue exchange.
- Message reaches a threshold read counter number, because it is not consumed. Sometimes this is called a "back out queue".
Q16. What is RabbitMQ Vhost?
Ans
A Virtual Host (a.k.a. ' vhost ') in AMQP is a namespace for objects such as Exchanges, Queues and Bindings. RabbitMQ utilizes more concrete implementation of virtual hosts, through effectively making them "virtual clusters" on top of the broker.
Q17. Which Protocol RabbitMQ uses?
Ans
RabbitMQ uses Advanced Message Queuing Protocol (AMQP). Its an open standard layer used to communicates date across network by means of byte stream.
Q18. What is Advanced Message Queuing Protocol (AMQP) ?
Ans
The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for message-oriented middleware. AMQP 0-9-1 is a binary messaging protocol and semantic framework for microservices and enterprise messaging. RabbitMQ is based on AMQP 0-9-1 Protocol. RabbitMQ supports -
- AMQP 0-9-1
- AMQP 1.0
- MQTT
- STOMP
- HTTP
RabbitMQ Messaging Flow- Bindings are what connects the exchanges to queues.
Q19. What is STOMP?
Ans
STOMP is a simple text-oriented messaging protocol used by our UI Client(browser) to connect to enterprise message brokers.
Clients can use the SEND or SUBSCRIBE commands to send or subscribe for messages along with a "destination" header that describes what the message is about and who should receive it.
It defines a protocol for clients and servers to communicate with messaging semantics. It does not define any implementation details, but rather addresses an easy-to-implement wire protocol for messaging integrations. The protocol is broadly similar to HTTP, and works over TCP using the following commands:
- CONNECT
- SEND
- SUBSCRIBE
- UNSUBSCRIBE
- BEGIN
- COMMIT
- ABORT
- ACK
- NACK
- DISCONNECT
Q20. How to delete all queues in RabbitMQ ?
Ans
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
Q21. How to implement RabbitMQ retry mechanism?
Ans
spring:
rabbitmq:
listener:
simple:
retry:
enabled: true
initial-interval: 6s
max-attempts: 5
max-interval: 15s
multiplier: 4
Q22. What Is Erlang? Why Is It Required For RabbitMQ?
Ans
Erlang is a general-purpose, concurrent, functional programming language, as well as a garbage-collected runtime system. The RabbitMQ server is written in the Erlang programming language and is built on the Open Telecom Platform framework for clustering and failover. Since RabbitMQ is built on top of Erlang, we will first need to install Erlang beforing installing RabbitMQ.
Q23. How to verify the version of RabbitMQ?
Ans
sudo rabbitmqctl status
Q24. How can we delete all the queues from RabbitMQ?
Ans
rabbitmqadmin list queues name
rabbitmqadmin delete queue name='queuename'
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
Q25. How do we stop the RabbitMQ server on localhost?
Ans
sudo -u rabbitmq rabbitmqctl stop
Q26. How to restart RabbitMQ service?
Ans
We can restart it like any other service:
sudo service rabbitmq-server restart
We get a specific control interface as well:
sudo rabbitmqctl "report"
sudo rabbitmqctl "reset"
Q27. In a remote procedure call, what is the unique identifier assigned to every request message?
Ans
CorelationId
Q28. What is the default port of the RabbitMQ management interface?
Ans
15672