BAEL-7523: small changes
This commit is contained in:
parent
8cd148b5b0
commit
e659b2fbfd
|
@ -8,6 +8,7 @@ import org.springframework.kafka.core.KafkaTemplate;
|
|||
import org.springframework.kafka.core.ProducerFactory;
|
||||
import org.springframework.kafka.core.KafkaOperations;
|
||||
import org.springframework.modulith.events.EventExternalizationConfiguration;
|
||||
import org.springframework.modulith.events.Externalized;
|
||||
import org.springframework.modulith.events.RoutingTarget;
|
||||
|
||||
@Configuration
|
||||
|
@ -23,19 +24,27 @@ class EventExternalizationConfig {
|
|||
)
|
||||
.mapping(
|
||||
ArticlePublishedEvent.class,
|
||||
it -> new ArticlePublishedKafkaEvent(it.slug(), it.title())
|
||||
it -> new PostPublishedKafkaEvent(it.slug(), it.title())
|
||||
)
|
||||
.route(
|
||||
WeeklySummaryPublishedEvent.class,
|
||||
it -> RoutingTarget.forTarget("baeldung.articles.published").andKey(it.handle())
|
||||
)
|
||||
.mapping(
|
||||
WeeklySummaryPublishedEvent.class,
|
||||
it -> new PostPublishedKafkaEvent(it.handle(), it.heading())
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
record ArticlePublishedKafkaEvent(String slug, String title) {
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
KafkaOperations<String, ArticlePublishedEvent> kafkaOperations(KafkaProperties kafkaProperties) {
|
||||
ProducerFactory<String, ArticlePublishedEvent> producerFactory = new DefaultKafkaProducerFactory<>(kafkaProperties.buildProducerProperties());
|
||||
return new KafkaTemplate<>(producerFactory);
|
||||
}
|
||||
|
||||
record PostPublishedKafkaEvent(String slug, String title) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.springmodulith.events.externalization;
|
||||
|
||||
import org.springframework.modulith.events.Externalized;
|
||||
|
||||
@Externalized
|
||||
record WeeklySummaryPublishedEvent(String handle, String heading) {
|
||||
}
|
Loading…
Reference in New Issue