Created
March 6, 2021 05:39
-
-
Save sheelprabhakar/353477a447fd8c8854608490083fa020 to your computer and use it in GitHub Desktop.
Spring boot application with KafkaListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootApplication | |
@EnableScheduling | |
public class Application { | |
@Autowired | |
private WeatherLogService weatherLogService; | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
@KafkaListener(topics = "weather-log2", groupId = "group-1", containerFactory = "kafkaListenerContainerFactory") | |
public void listenGroupFoo(WeatherInfo record) { | |
System.out.println("Received Message in group foo: " + record.getTemp()); | |
try { | |
weatherLogService.saveLogs(new WeatherLog(record.getCity(), record.getLatitude(), record.getLongitude() | |
, BigDecimal.valueOf(record.getTemp()), record.getLogDate())); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment