Listening to a Kafka topic

Let's create a listener NotificationListener class that will be used to listen to messages on the Kafka notification topic and send email and SMS notifications to the customer:

@Componentpublic class NotificationListener {@StreamListener(NotificationStreams.INPUT)public void sendMailNotification(@Payload Notification notification) {System.out.println("Sent notification to email: "+notification.getEmail()+" Message: "+notification.getMessage());}@StreamListener(NotificationStreams.INPUT)public void sendSMSNotification(@Payload Notification notification) {System.out.println("Notified with SMS to mobile: "+notification.getMobile()+" Message: "+notification.getMessage());}}

The NotificationListener class has two methods— ...

Get Mastering Spring Boot 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.