Skip to content

Instantly share code, notes, and snippets.

@sheelprabhakar
Created March 6, 2021 05:01
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/492f834bcfd11d6d9325f8bb9d739fa6 to your computer and use it in GitHub Desktop.
Save sheelprabhakar/492f834bcfd11d6d9325f8bb9d739fa6 to your computer and use it in GitHub Desktop.
Kafka Spring config for producer
@Configuration
public class KafkaProducerConfig {
@Value( "${kafka.bootstrapAddress}" )
private String bootstrapAddress;
@Bean
public ProducerFactory<String, WeatherInfo> producerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
bootstrapAddress);
configProps.put(
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
StringSerializer.class);
configProps.put(
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
JsonSerializer.class);
return new DefaultKafkaProducerFactory<>(configProps);
}
@Bean
public KafkaTemplate<String, WeatherInfo> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment