You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reactive-commons/9-configuration-properties.md
+35-18Lines changed: 35 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -275,15 +275,21 @@ public AsyncKafkaPropsDomain.KafkaSecretFiller customKafkaFiller() {
275
275
</Tabs>
276
276
277
277
## Mandatory property in RabbitMQ
278
-
The mandatory property is a message publishing parameter in RabbitMQ that determines the behavior when a message cannot be routed to any queue. This can happen if there are no queues bound to the exchange or if the routing key does not match any of the available queues.
279
278
280
-
By default, this option is disabled, but if activated (`mandatory = true`), it works right after the message is published to an exchange, but before it is routed to a queue.
279
+
The mandatory property is a message publishing parameter in RabbitMQ that determines the behavior when a message cannot
280
+
be routed to any queue. This can happen if there are no queues bound to the exchange or if the routing key does not
281
+
match any of the available queues.
281
282
282
-
When a message is published with `mandatory = true`, RabbitMQ will try to route it from the exchange to one or more queues. If no queue receives the message, then:
283
+
By default, this option is disabled, but if activated (`mandatory = true`), it works right after the message is
284
+
published to an exchange, but before it is routed to a queue.
285
+
286
+
When a message is published with `mandatory = true`, RabbitMQ will try to route it from the exchange to one or more
287
+
queues. If no queue receives the message, then:
283
288
284
289
- The message is not lost, but it is not delivered to any queue.
285
290
- RabbitMQ triggers a basic.return event on the producer's channel.
286
-
- The producer must have a ReturnListener or an equivalent handler to receive and process the returned message. If one is not defined, the message is lost.
291
+
- The producer must have a ReturnListener or an equivalent handler to receive and process the returned message. If one
292
+
is not defined, the message is lost.
287
293
288
294
#### Example
289
295
@@ -297,19 +303,27 @@ Result:
297
303
298
304
- If there is no queue bound with `order.cancelled`, the message is not routed.
299
305
- Since `mandatory = true`, RabbitMQ tries to return it to the producer.
300
-
- If there is a ReturnListener, this message can be captured and handled, for example, by sending it to another consumer's queue, DLQ queues, saving it in a log file, or in a database.
306
+
- If there is a ReturnListener, this message can be captured and handled, for example, by sending it to another
307
+
- consumer's queue, DLQ queues, saving it in a log file, or in a database.
301
308
302
309
### Advantages
303
310
304
-
- Early detection of routing errors: Prevents critical messages from "disappearing" without a trace, which facilitates the identification of erroneous configurations in bindings or patterns.
305
-
- Integrity and reliability: Ensures that each message finds a consumer or, failing that, returns to the producer for alternative handling (DLQ queues, logs, database).
306
-
- Operational visibility: Facilitates metrics of "unrouted messages" and alerts when the event flow does not follow the planned routes.
311
+
- Early detection of routing errors: Prevents critical messages from "disappearing" without a trace, which facilitates
312
+
the identification of erroneous configurations in bindings or patterns.
313
+
- Integrity and reliability: Ensures that each message finds a consumer or, failing that, returns to the producer for
314
+
alternative handling (DLQ queues, logs, database).
315
+
- Operational visibility: Facilitates metrics of "unrouted messages" and alerts when the event flow does not follow the
316
+
planned routes.
307
317
308
318
### Considerations
309
319
310
-
Although this property does not prevent performance problems or degradation of the RabbitMQ cluster, it is useful for preventing the loss of unrouted messages and for detecting configuration errors in routing.
320
+
Although this property does not prevent performance problems or degradation of the RabbitMQ cluster, it is useful for
321
+
preventing the loss of unrouted messages and for detecting configuration errors in routing.
311
322
312
-
When mandatory is active, under normal conditions (all routes exist), there is practically no impact. In anomalous situations, there will be additional return traffic for each unroutable message. This implies an extra load for both RabbitMQ (which must send the message back to the producer) and the sending application (which must process the returned message).
323
+
When mandatory is active, under normal conditions (all routes exist), there is practically no impact. In anomalous
324
+
situations, there will be additional return traffic for each unroutable message. This implies an extra load for both
325
+
RabbitMQ (which must send the message back to the producer) and the sending application (which must process the returned
326
+
message).
313
327
314
328
### Implementation
315
329
@@ -322,8 +336,10 @@ app:
322
336
mandatory: true # enable mandatory property
323
337
```
324
338
325
-
Now we configure the return handler to manage messages that could not be delivered correctly. By default, these messages are displayed in a log.
326
-
To customize this behavior, a class that implements the `UnroutableMessageHandler` interface is created and registered as a Spring bean:
339
+
Now we configure the return handler to manage messages that could not be delivered correctly. By default, these messages
340
+
are displayed in a log.
341
+
To customize this behavior, a class that implements the `UnroutableMessageHandler` interface is created and registered
342
+
as a Spring bean:
327
343
328
344
```java
329
345
package sample;
@@ -354,7 +370,7 @@ public class ResendUnroutableMessageHandler implements UnroutableMessageHandler
354
370
+ ", body=" + new String(returned.getBody(), StandardCharsets.UTF_8)
0 commit comments