Skip to content

Instantly share code, notes, and snippets.

@aytekin
Created November 18, 2021 20:21
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 aytekin/b058788de19322dc433c0ff20ab70586 to your computer and use it in GitHub Desktop.
Save aytekin/b058788de19322dc433c0ff20ab70586 to your computer and use it in GitHub Desktop.
reactor-kafka
@Configuration
@AllArgsConstructor
public class KafkaProducer {
private static final String BOOTSTRAP_SERVERS = "localhost:9092";
/**
* Building kafka producer configurations
* */
@Bean
public Map<String, Object> bootstrapConfig() {
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ProducerConfig.CLIENT_ID_CONFIG, "sample-producer");
props.put(ProducerConfig.ACKS_CONFIG, "all");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, IntegerSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return props;
}
/**
* Creating reactive kafka Producer template with producer configurations
* */
@Bean
public ReactiveKafkaProducerTemplate<Integer, String> kafkaSender() {
return new ReactiveKafkaProducerTemplate<>(SenderOptions.create(bootstrapConfig()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment