Skip to content

Instantly share code, notes, and snippets.

@sheelprabhakar
Created March 6, 2021 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheelprabhakar/353477a447fd8c8854608490083fa020 to your computer and use it in GitHub Desktop.
Save sheelprabhakar/353477a447fd8c8854608490083fa020 to your computer and use it in GitHub Desktop.
Spring boot application with KafkaListener
@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