public void listen(String message) {
if(message.contains("fail")) {
throw new RuntimeException("Processing failed");
}
System.out.println("Processed: " + message);
}When a message is rejected without requeue in RabbitMQ with DLQ configured, it is routed to the dead letter queue. This allows later inspection or handling of failed messages.
Dead letter queues are set by adding the x-dead-letter-exchange argument to the queue declaration. Option C shows the correct way to do this using @QueueBinding and @Argument.
When the retry attempts are exhausted, the message is routed to the dead letter queue to avoid infinite retry loops and allow manual or automated handling.
If the original queue does not have the x-dead-letter-exchange argument, RabbitMQ does not know where to route rejected messages, so the DLQ will not receive them.
Dead letter queues allow failed messages to be separated from the main queue so they can be inspected or reprocessed later without blocking or crashing the main message processing.