BAEL-7523: small changes

This commit is contained in:
emanueltrandafir1993 2024-02-07 23:00:56 +01:00 committed by emanuel.trandafir
parent 8cd148b5b0
commit e659b2fbfd
2 changed files with 21 additions and 5 deletions

View File

@ -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) {
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.springmodulith.events.externalization;
import org.springframework.modulith.events.Externalized;
@Externalized
record WeeklySummaryPublishedEvent(String handle, String heading) {
}