use of org.springframework.kafka.listener.ContainerProperties in project team-catalog by navikt.
the class KafkaConfig method nomRessursContainer.
@Bean
public KafkaMessageListenerContainer<String, String> nomRessursContainer(@Value("${kafka.topics.nom-ressurs}") String topic, NomClient nomClient, MeterRegistry meterRegistry) {
var containerProps = new ContainerProperties(topic);
containerProps.setMessageListener(new NomListener(nomClient));
containerProps.setAckMode(AckMode.MANUAL);
containerProps.setPollTimeout(500);
var props = consumerProps(StringDeserializer.class, "nom-cons");
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, "100");
var cf = new DefaultKafkaConsumerFactory<String, String>(props);
cf.addListener(new MicrometerConsumerListener<>(meterRegistry));
var container = new KafkaMessageListenerContainer<>(cf, containerProps);
container.setBatchErrorHandler(new KafkaErrorHandler());
container.getContainerProperties().setAuthorizationExceptionRetryInterval(Duration.ofMinutes(5));
return container;
}
use of org.springframework.kafka.listener.ContainerProperties in project spring-kafka-study by MinChul-Son.
the class MessageListenerContainerConfig method kafkaMessageListenerContainer.
@Bean
public KafkaMessageListenerContainer<String, String> kafkaMessageListenerContainer() {
ContainerProperties containerProps = new ContainerProperties("test4");
containerProps.setGroupId("test4-container");
containerProps.setAckMode(ContainerProperties.AckMode.BATCH);
containerProps.setMessageListener(new DefaultMessageListener());
KafkaMessageListenerContainer<String, String> container = new KafkaMessageListenerContainer<>(containerFactory(), containerProps);
container.setAutoStartup(false);
return container;
}
use of org.springframework.kafka.listener.ContainerProperties in project skywalking-java by apache.
the class CaseController method setUpConsumer.
private void setUpConsumer() {
Map<String, Object> configs = new HashMap<>();
configs.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
configs.put(ConsumerConfig.GROUP_ID_CONFIG, "grop:" + topicName);
configs.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
Deserializer<String> stringDeserializer = new StringDeserializer();
DefaultKafkaConsumerFactory<String, String> factory = new DefaultKafkaConsumerFactory(configs, stringDeserializer, stringDeserializer);
ContainerProperties props = new ContainerProperties(topicName);
props.setMessageListener(new AcknowledgingMessageListener<String, String>() {
@Override
public void onMessage(ConsumerRecord<String, String> data, Acknowledgment acknowledgment) {
if (data.value().equals(helloWorld)) {
OkHttpClient client = new OkHttpClient.Builder().build();
Request request = new Request.Builder().url("http://localhost:8080/spring-kafka-2.3.x-scenario/case/spring-kafka-consumer-ping").build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
}
response.body().close();
acknowledgment.acknowledge();
latch.countDown();
}
}
});
KafkaMessageListenerContainer<String, String> container = new KafkaMessageListenerContainer<>(factory, props);
container.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
container.start();
}
use of org.springframework.kafka.listener.ContainerProperties in project core-services by digit-egov.
the class CoreIndexConsumerConfig method container.
public KafkaMessageListenerContainer<String, String> container() throws Exception {
setTopics();
// set more properties
ContainerProperties properties = new ContainerProperties(this.topics);
// properties.setPauseEnabled(true);
// properties.setPauseAfter(0);
properties.setMessageListener(indexerMessageListener);
log.info("Custom KafkaListenerContainer built...");
return new KafkaMessageListenerContainer<>(consumerFactory(), properties);
}
use of org.springframework.kafka.listener.ContainerProperties in project core-services by digit-egov.
the class ReindexConsumerConfig method container.
public KafkaMessageListenerContainer<String, String> container() throws Exception {
setTopics();
// set more properties
ContainerProperties properties = new ContainerProperties(this.topics);
// properties.setPauseEnabled(true);
// properties.setPauseAfter(0);
properties.setMessageListener(indexerMessageListener);
log.info("Reindex KafkaListenerContainer built...");
return new KafkaMessageListenerContainer<>(consumerFactory(), properties);
}
Aggregations