for test change kafka producer to single object after back to list of object in future
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.example.mmad.testapp.kafkaProducerConfig;
|
||||
|
||||
import com.example.mmad.testapp.event.UserCreatedEvent;
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -17,7 +18,7 @@ import java.util.Map;
|
||||
public class KafkaProducerConfig {
|
||||
|
||||
@Bean
|
||||
public ProducerFactory<String, List<?>> producerFactory() {
|
||||
public ProducerFactory<String, UserCreatedEvent> producerFactory() {
|
||||
Map<String, Object> configProps = new HashMap<>();
|
||||
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); // Replace with your Kafka broker address
|
||||
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||
@ -26,7 +27,7 @@ public class KafkaProducerConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaTemplate<String, List<?>> kafkaTemplate() {
|
||||
public KafkaTemplate<String, UserCreatedEvent> kafkaTemplate() {
|
||||
return new KafkaTemplate<>(producerFactory());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
@Component
|
||||
public class UserQueryHandler {
|
||||
private static final String kafkaTopic = "user-commanded";
|
||||
private static final String kafkaTopic = "user-created";
|
||||
private final KafkaProducerConfig kafkaProducer;
|
||||
|
||||
public UserQueryHandler(KafkaProducerConfig kafkaProducer) {
|
||||
@ -20,7 +20,7 @@ public class UserQueryHandler {
|
||||
@Async("taskExecutor")
|
||||
@EventListener
|
||||
public void handelUserCreated(UserCreatedEvent event) {
|
||||
kafkaProducer.kafkaTemplate().send(kafkaTopic, (List<?>) event);
|
||||
kafkaProducer.kafkaTemplate().send(kafkaTopic, event);
|
||||
// persist in query data base
|
||||
System.out.println("Received user created event" + event.getUserId());
|
||||
}
|
||||
|
Reference in New Issue
Block a user