Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa authored Dec 26, 2024
1 parent c208384 commit fc3d7e8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ZenWave Spring-Modulith Events Externalizer for Spring Cloud Stream
# Spring-Modulith Events Externalizer for Spring Cloud Stream

[![Maven Central](https://img.shields.io/maven-central/v/io.zenwave360.sdk/spring-modulith-events-scs.svg?label=Maven%20Central&logo=apachemaven)](https://search.maven.org/artifact/io.zenwave360.sdk/spring-modulith-events-scs)
[![build](https://github.com/ZenWave360/spring-modulith-events-spring-cloud-stream/workflows/Build/badge.svg)](https://github.com/ZenWave360/spring-modulith-events-spring-cloud-stream/actions/workflows/build.yml)
Expand Down Expand Up @@ -32,12 +32,14 @@ public class SpringCloudStreamEventsConfig {
}
```

This configuration ensures that all events of type `org.springframework.messaging.Message` with the header `SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_EVENT_HEADER` will be routed to their specified destination.
This configuration ensures that all events of type `org.springframework.messaging.Message` with the header `SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_EVENT_HEADER` will be externalized and routed to their specified destination.

---

## Event Serialization

Using the transactional event publication log requires serializing events to a format that can be stored in a database. This library provides support for JSON and Avro serialization formats of `Message<?>` payloads.

### JSON Serialization
Provides an `EventSerializer` that serializes `Message<?>` payloads into JSON format suitable for data storage adding a `_class` field to indicate the class type of the payload (needed for deserialization).

Expand All @@ -49,7 +51,7 @@ If `com.fasterxml.jackson.dataformat.avro.AvroMapper` is present in the classpat
## Routing Events

### Programmatic Routing
You can define routing targets programmatically using Spring Messages:
You can define routing targets programmatically using a Message header:

```java
public class CustomerEventsProducer implements ICustomerEventsProducer {
Expand All @@ -58,15 +60,17 @@ public class CustomerEventsProducer implements ICustomerEventsProducer {

public void onCustomerCreated(CustomerCreated event) {
Message<CustomerCreated> message = MessageBuilder.withPayload(event)
.setHeader(SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, "customer-created")
.setHeader(
SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER,
"customer-created") // <- target binding name
.build();
applicationEventPublisher.publishEvent(message);
}
}
```

### Annotation-Based Routing
Leverage the `@Externalized` annotation to define routing dynamically:
Leverage the `@Externalized` annotation to define the target binding name and routing key:

```java
@Externalized("customer-created::#{#this.getLastname()}")
Expand All @@ -89,7 +93,7 @@ spring:
destination: customer-created
```
With this configuration, the `SpringCloudStreamEventExternalizer` dynamically sets the routing key (e.g., `kafka_messageKey` or `rabbit_routingKey`) based on the channel binder.
`SpringCloudStreamEventExternalizer` dynamically sets the appropriate routing key (e.g., `kafka_messageKey` or `rabbit_routingKey`) based on the channel binder.

---

Expand Down

0 comments on commit fc3d7e8

Please sign in to comment.