What is the publish-subscribe pattern in RabbitMQ?
It is a messaging pattern where messages are sent by a publisher to an exchange, which then broadcasts the messages to multiple queues bound to it. Consumers receive messages from these queues independently.
Click to reveal answer
beginner
What type of exchange is used for broadcasting messages in RabbitMQ?
A fanout exchange is used for broadcasting. It sends messages to all queues bound to it without considering any routing keys.
Click to reveal answer
beginner
How do queues receive messages in a publish-subscribe setup?
Queues are bound to the exchange. When the exchange receives a message, it forwards the message to all bound queues, allowing multiple consumers to get the same message.
Click to reveal answer
intermediate
What command creates a fanout exchange named 'logs' in RabbitMQ?
B. The exchange type should be 'direct' instead of 'fanout'
C. The routing_key is missing
D. The queues are declared incorrectly
Solution
Step 1: Check queue bindings
Only 'queue1' is bound to the 'logs' exchange; 'queue2' is not bound.
Step 2: Understand fanout behavior
Fanout sends messages to all bound queues, so unbound queues won't get messages.
Final Answer:
Queue 'queue2' is not bound to the exchange -> Option A
Quick Check:
All queues must be bound to receive messages [OK]
Hint: Bind all queues to exchange to receive broadcasts [OK]
Common Mistakes:
Assuming routing_key is needed for fanout
Changing exchange type unnecessarily
Not binding all queues
5. You want to broadcast logs to multiple services dynamically. Which approach best ensures each service gets its own queue and receives all messages without interfering with others?
hard
A. Services publish messages directly to each other's queues
B. All services share a single queue bound to a direct exchange
C. Each service creates a queue bound to a topic exchange with different routing keys
D. Each service creates a unique queue and binds it to a shared fanout exchange
Solution
Step 1: Understand publish-subscribe pattern
Fanout exchange broadcasts messages to all bound queues, ideal for multiple receivers.
Step 2: Ensure isolation and dynamic addition
Each service having its own queue bound to the fanout exchange ensures independent consumption and easy scaling.
Step 3: Evaluate other options
Sharing a single queue causes message competition; topic exchange with routing keys is more selective, not broadcast; direct publishing is complex and error-prone.
Final Answer:
Each service creates a unique queue and binds it to a shared fanout exchange -> Option D
Quick Check:
Fanout + unique queues = broadcast to all [OK]
Hint: Use fanout exchange with unique queues per service [OK]
Common Mistakes:
Using a single shared queue causing message loss
Confusing topic exchange for broadcast
Direct publishing to queues instead of exchange
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.