Skip to content

Commit f1ae32b

Browse files
ciberkleidodrotbohm
authored andcommitted
GH-914 - Mention message header support in event externalization documentation.
1 parent 85c5206 commit f1ae32b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/docs/antora/modules/ROOT/pages/events.adoc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ The event externalization performs three steps on each application event publish
393393

394394
1. _Determining whether the event is supposed to be externalized_ -- We refer to this as "`event selection`".
395395
By default, only event types located within a Spring Boot auto-configuration package and annotated with one of the supported `@Externalized` annotations are selected for externalization.
396-
2. _Mapping the event (optional)_ -- By default, the event is serialized to JSON using the Jackson `ObjectMapper` present in the application and published as is.
397-
The mapping step allows developers to either customize the representation or even completely replace the original event with a representation suitable for external parties.
398-
Note that the mapping step precedes the actual serialization of the to be published object.
396+
2. _Preparing the message (optional)_ -- By default, the event is serialized as is by the corresponding broker infrastructure.
397+
An optional mapping step allows developers to customize or even completely replace the original event with a payload suitable for external parties.
398+
For Kafka and AMQP, developers can also add headers to the message to be published.
399399
3. _Determining a routing target_ -- Message broker clients need a logical target to publish the message to.
400400
The target usually identifies physical infrastructure (a topic, exchange, or queue depending on the broker) and is often statically derived from the event type.
401401
Unless defined in the `@Externalized` annotation specifically, Spring Modulith uses the application-local type name as target.
@@ -481,7 +481,8 @@ class ExternalizationConfiguration {
481481
return EventExternalizationConfiguration.externalizing() // <1>
482482
.select(EventExternalizationConfiguration.annotatedAsExternalized()) // <2>
483483
.mapping(SomeEvent.class, event -> …) // <3>
484-
.routeKey(WithKeyProperty.class, WithKeyProperty::getKey) // <4>
484+
.headers(event -> …) // <4>
485+
.routeKey(WithKeyProperty.class, WithKeyProperty::getKey) // <5>
485486
.build();
486487
}
487488
}
@@ -498,8 +499,9 @@ class ExternalizationConfiguration {
498499
499500
EventExternalizationConfiguration.externalizing() // <1>
500501
.select(EventExternalizationConfiguration.annotatedAsExternalized()) // <2>
501-
.mapping(SomeEvent::class.java) { event -> … } // <3>
502-
.routeKey(WithKeyProperty::class.java, WithKeyProperty::getKey) // <4>
502+
.mapping(SomeEvent::class.java) { event -> … } // <3>
503+
.headers() { event -> … } // <4>
504+
.routeKey(WithKeyProperty::class.java, WithKeyProperty::getKey) // <5>
503505
.build()
504506
}
505507
}
@@ -513,7 +515,8 @@ Convenience methods to easily select events by type, by packages, packages and a
513515
Also, a shortcut to define selection and routing in one step.
514516
<3> We define a mapping step for `SomeEvent` instances.
515517
Note that the routing will still be determined by the original event instance, unless you additionally call `….routeMapped()` on the router.
516-
<4> We finally determine a routing key by defining a method handle to extract a value of the event instance.
518+
<4> We add custom headers to the message to be sent out either generally as shown or specific to a certain payload type.
519+
<5> We finally determine a routing key by defining a method handle to extract a value of the event instance.
517520
Alternatively, a full `RoutingKey` can be produced for individual events by using the general `route(…)` method on the `Router` instance returned from the previous call.
518521

519522
[[testing]]

0 commit comments

Comments
 (0)