Bird
Raised Fist0
Spring Bootframework~10 mins

Dead letter queues in Spring Boot - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a dead letter queue in Spring Boot.

Spring Boot
Queue deadLetterQueue() {
    return new Queue("[1]", true);
}
Drag options to blanks, or click blank then click option'
AmainQueue
BmyDeadLetterQueue
CprocessingQueue
DretryQueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the main queue name instead of a dead letter queue name.
Using a retry queue name which is different from dead letter queue.
2fill in blank
medium

Complete the code to bind the dead letter queue to the dead letter exchange.

Spring Boot
Binding deadLetterBinding(Queue deadLetterQueue, DirectExchange deadLetterExchange) {
    return BindingBuilder.bind(deadLetterQueue).to(deadLetterExchange).with("[1]");
}
Drag options to blanks, or click blank then click option'
AretryRoutingKey
BprocessingRoutingKey
CmainRoutingKey
DdeadLetterRoutingKey
Attempts:
3 left
💡 Hint
Common Mistakes
Using the main routing key instead of the dead letter routing key.
Using the retry routing key which is unrelated.
3fill in blank
hard

Fix the error in the queue declaration to enable dead letter exchange support.

Spring Boot
Map<String, Object> args = new HashMap<>();
args.put("[1]", "deadLetterExchange");
Queue queue = new Queue("mainQueue", true, false, false, args);
Drag options to blanks, or click blank then click option'
Ax-dead-letter-exchange
Bx-message-ttl
Cx-max-length
Dx-priority
Attempts:
3 left
💡 Hint
Common Mistakes
Using TTL or max length keys instead of dead letter exchange key.
Forgetting to set the dead letter exchange argument.
4fill in blank
hard

Fill both blanks to configure a queue with dead letter exchange and dead letter routing key.

Spring Boot
Map<String, Object> args = new HashMap<>();
args.put("[1]", "deadLetterExchange");
args.put("[2]", "deadLetterRoutingKey");
Queue queue = new Queue("mainQueue", true, false, false, args);
Drag options to blanks, or click blank then click option'
Ax-dead-letter-exchange
Bx-message-ttl
Cx-dead-letter-routing-key
Dx-max-length
Attempts:
3 left
💡 Hint
Common Mistakes
Using TTL or max length keys instead of dead letter keys.
Mixing up the routing key and exchange keys.
5fill in blank
hard

Fill all three blanks to create a dead letter queue, dead letter exchange, and bind them with a routing key.

Spring Boot
Queue deadLetterQueue() {
    return new Queue("[1]", true);
}

DirectExchange deadLetterExchange() {
    return new DirectExchange("[2]");
}

Binding deadLetterBinding() {
    return BindingBuilder.bind(deadLetterQueue()).to(deadLetterExchange()).with("[3]");
}
Drag options to blanks, or click blank then click option'
AmyDeadLetterQueue
BdeadLetterExchange
CdeadLetterRoutingKey
DmainQueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using main queue or unrelated names for dead letter components.
Mismatching routing key and binding key.

Practice

(1/5)
1. What is the main purpose of a Dead Letter Queue (DLQ) in Spring Boot messaging?
easy
A. To speed up message processing by duplicating messages
B. To hold messages that failed processing and prevent blocking the main queue
C. To permanently delete messages after processing
D. To encrypt messages for security

Solution

  1. Step 1: Understand message failure handling

    Dead Letter Queues are designed to store messages that cannot be processed successfully.
  2. Step 2: Identify the role of DLQ in queue management

    DLQs keep the main queue clean by isolating failed messages, allowing the system to continue processing other messages.
  3. Final Answer:

    To hold messages that failed processing and prevent blocking the main queue -> Option B
  4. Quick Check:

    DLQ purpose = hold failed messages [OK]
Hint: DLQ stores failed messages to keep main queue flowing [OK]
Common Mistakes:
  • Thinking DLQ speeds up processing by duplicating messages
  • Confusing DLQ with message deletion
  • Assuming DLQ encrypts messages
2. Which of the following is the correct way to configure a Dead Letter Queue in Spring Boot using RabbitMQ?
easy
A. Set queue argument x-dead-letter-exchange and x-dead-letter-routing-key
B. Set queue argument x-message-ttl only
C. Use @EnableDeadLetterQueue annotation on the listener
D. Configure spring.rabbitmq.dlq.enabled=true in application.properties

Solution

  1. Step 1: Identify DLQ configuration parameters

    Dead Letter Queues require setting the queue arguments x-dead-letter-exchange and x-dead-letter-routing-key to route failed messages.
  2. Step 2: Eliminate incorrect options

    x-message-ttl controls message time-to-live, not DLQ; no @EnableDeadLetterQueue annotation exists; no direct property spring.rabbitmq.dlq.enabled.
  3. Final Answer:

    Set queue argument x-dead-letter-exchange and x-dead-letter-routing-key -> Option A
  4. Quick Check:

    DLQ config = x-dead-letter-exchange + routing key [OK]
Hint: DLQ needs dead-letter-exchange and routing-key set [OK]
Common Mistakes:
  • Confusing TTL with DLQ configuration
  • Looking for non-existent annotations
  • Expecting simple property toggle for DLQ
3. Given this Spring Boot RabbitMQ listener configuration, what happens when message processing throws an exception?
@RabbitListener(queues = "mainQueue")
public void listen(String msg) {
  if(msg.contains("fail")) throw new RuntimeException("Fail");
  System.out.println("Processed: " + msg);
}
Assuming mainQueue has a DLQ configured, what is the expected behavior?
medium
A. The message is retried infinitely without moving to DLQ
B. The application crashes immediately
C. The message is lost without any logging
D. The failed message is sent to the Dead Letter Queue and processing continues

Solution

  1. Step 1: Understand exception handling in RabbitMQ listener

    When an exception occurs, the message is rejected and, if DLQ is configured, routed there.
  2. Step 2: Confirm system behavior with DLQ

    The failed message goes to the Dead Letter Queue, allowing the main queue to continue processing other messages.
  3. Final Answer:

    The failed message is sent to the Dead Letter Queue and processing continues -> Option D
  4. Quick Check:

    Exception triggers DLQ routing [OK]
Hint: Exception sends message to DLQ if configured [OK]
Common Mistakes:
  • Assuming app crashes on exception
  • Thinking message is lost silently
  • Believing infinite retries without DLQ
4. You configured a Dead Letter Queue but messages are not arriving there after failures. Which of the following is the most likely cause?
medium
A. The message payload is empty
B. The listener method does not throw exceptions
C. The main queue is missing the x-dead-letter-exchange argument
D. The DLQ name is too long

Solution

  1. Step 1: Check DLQ configuration completeness

    If the main queue lacks the x-dead-letter-exchange argument, failed messages have no route to DLQ.
  2. Step 2: Evaluate other options

    Listener throwing exceptions is needed but not sufficient; DLQ name length and empty payload do not prevent DLQ routing.
  3. Final Answer:

    The main queue is missing the x-dead-letter-exchange argument -> Option C
  4. Quick Check:

    Missing DLX argument blocks DLQ routing [OK]
Hint: DLQ needs dead-letter-exchange set on main queue [OK]
Common Mistakes:
  • Ignoring missing DLX argument
  • Blaming listener behavior alone
  • Worrying about DLQ name length unnecessarily
5. You want to implement a retry mechanism for failed messages before sending them to the Dead Letter Queue in Spring Boot. Which approach correctly combines retries and DLQ usage?
hard
A. Use a retry interceptor on the listener and configure DLQ for messages failing all retries
B. Send all messages directly to DLQ and manually retry them later
C. Disable DLQ and rely only on retry count in listener
D. Configure DLQ without retry; retries happen automatically by RabbitMQ

Solution

  1. Step 1: Understand retry and DLQ roles

    Retries allow multiple attempts to process a message before considering it failed.
  2. Step 2: Combine retry interceptor with DLQ

    Configure a retry interceptor on the listener to retry processing; if all retries fail, the message is routed to the DLQ.
  3. Step 3: Eliminate incorrect options

    Sending all messages directly to DLQ skips normal processing; disabling DLQ loses failed message tracking; RabbitMQ does not retry automatically without app logic.
  4. Final Answer:

    Use a retry interceptor on the listener and configure DLQ for messages failing all retries -> Option A
  5. Quick Check:

    Retry interceptor + DLQ = robust failure handling [OK]
Hint: Retry in listener, then DLQ for final failures [OK]
Common Mistakes:
  • Sending all messages directly to DLQ
  • Disabling DLQ and expecting retries only
  • Assuming RabbitMQ retries automatically
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard