SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package in.springframework.blog.tutorials.listeners;
  2.  
  3. import org.apache.logging.log4j.LogManager;
  4. import org.apache.logging.log4j.Logger;
  5. import org.springframework.kafka.annotation.KafkaListener;
  6. import org.springframework.kafka.support.KafkaHeaders;
  7. import org.springframework.messaging.handler.annotation.Header;
  8. import org.springframework.messaging.handler.annotation.Payload;
  9. import org.springframework.stereotype.Component;
  10.  
  11. @Component
  12. public class KafkaMessageListener {
  13.  
  14.     Logger logger = LogManager.getLogger(KafkaMessageListener.class);
  15.     @KafkaListener(topics = "FirstTopic", containerFactory = "firstTopicListenerContainerFactory")
  16.     public void processFirstTopicMessage(@Payload String content,
  17.                                          @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition,
  18.                                          @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
  19.  
  20.         logger.info(String.format("Received %s message for partition %d ", topic, partition) + content);
  21.     }
  22.     @KafkaListener(topics = "SecondTopic", containerFactory = "secondTopicListenerContainerFactory")
  23.     public void processSecondTopicMessage(@Payload String content,
  24.                                           @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition,
  25.                                           @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
  26.  
  27.         logger.info(String.format("Received %s message for partition %d ", topic, partition) + content);
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top