Skip to content

Commit f50adda

Browse files
committed
docs: improve formatting and readability of mandatory property documentation
1 parent 51ec18a commit f50adda

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

docs/docs/reactive-commons/9-configuration-properties.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,21 @@ public AsyncKafkaPropsDomain.KafkaSecretFiller customKafkaFiller() {
275275
</Tabs>
276276

277277
## 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.
279278

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.
281282

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:
283288

284289
- The message is not lost, but it is not delivered to any queue.
285290
- 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.
287293

288294
#### Example
289295

@@ -297,19 +303,27 @@ Result:
297303

298304
- If there is no queue bound with `order.cancelled`, the message is not routed.
299305
- 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.
301308

302309
### Advantages
303310

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.
307317

308318
### Considerations
309319

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.
311322

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).
313327

314328
### Implementation
315329

@@ -322,8 +336,10 @@ app:
322336
mandatory: true # enable mandatory property
323337
```
324338

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:
327343

328344
```java
329345
package sample;
@@ -354,7 +370,7 @@ public class ResendUnroutableMessageHandler implements UnroutableMessageHandler
354370
+ ", body=" + new String(returned.getBody(), StandardCharsets.UTF_8)
355371
+ ", properties=" + returned.getProperties()
356372
);
357-
373+
358374
// Process the unroutable message
359375
return useCase.sendMessage(new String(returned.getBody(), StandardCharsets.UTF_8));
360376
}
@@ -421,7 +437,7 @@ public class ResendUnroutableMessageHandler implements UnroutableMessageHandler
421437
// Use the DomainEvent class for domain events and the AsyncQuery class for asynchronous queries.
422438
Command<JsonNode> command = objectMapper.readValue(returned.getBody(), new TypeReference<>() {
423439
});
424-
440+
425441
// Send the message to the queue
426442
return emitCommand(command.getName(), command.getCommandId(), command.getData())
427443
.doOnError(e -> log.severe("Failed to send the returned message: " + e.getMessage()));
@@ -433,7 +449,8 @@ public class ResendUnroutableMessageHandler implements UnroutableMessageHandler
433449
}
434450
```
435451

436-
In the RabbitMQ configuration class, we create the `UnroutableMessageProcessor` bean to register the unrouted message handler.
452+
In the RabbitMQ configuration class, we create the `UnroutableMessageProcessor` bean to register the unrouted message
453+
handler.
437454

438455
```java
439456
package sample;
@@ -509,9 +526,9 @@ public class RabbitMQConfig {
509526
@Bean
510527
UnroutableMessageProcessor registerUnroutableMessageHandler(UnroutableMessageNotifier unroutableMessageNotifier,
511528
ResendUnroutableMessageHandler handler) {
512-
var factory = new UnroutableMessageProcessor();
513-
unroutableMessageNotifier.listenToUnroutableMessages(handler);
514-
return factory;
529+
var factory = new UnroutableMessageProcessor();
530+
unroutableMessageNotifier.listenToUnroutableMessages(handler);
531+
return factory;
515532
}
516533
517534
}

0 commit comments

Comments
 (0)