Skip to content

Commit

Permalink
removed java config and using default container factory
Browse files Browse the repository at this point in the history
  • Loading branch information
purbarunc committed Aug 1, 2024
1 parent e0ef274 commit f2b5222
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,4 @@ public class SbKafkaConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(SbKafkaConsumerApplication.class, args);
}

@Bean
ConsumerFactory<String, OrderMessage> consumerFactory() {

// Creating a map of string-object type
Map<String, Object> config = new HashMap<>();

// Adding the Configuration
config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
config.put(ConsumerConfig.GROUP_ID_CONFIG, "NEW_ORDER_group");
config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);

// Returning message in JSON format
return new DefaultKafkaConsumerFactory<>(config, new StringDeserializer(),
new JsonDeserializer<>(OrderMessage.class));
}

// Creating a Listener
@Bean
ConcurrentKafkaListenerContainerFactory<String, OrderMessage> orderListener() {
ConcurrentKafkaListenerContainerFactory<String, OrderMessage> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
return factory;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Service
public class KafkaConsumer {
@KafkaListener(groupId = "NEW_ORDER_group", topics = "NEW_ORDER",containerFactory = "orderListener")
@KafkaListener(groupId = "NEW_ORDER_group", topics = "NEW_ORDER")
public void consume(OrderMessage orderMessage,Acknowledgment acknowledgment) {
System.out.println(orderMessage);
acknowledgment.acknowledge();
Expand Down

0 comments on commit f2b5222

Please sign in to comment.