use of org.springframework.kafka.listener.config.ContainerProperties in project loc-framework by lord-of-code.
the class LocKafkaAutoConfiguration method kafkaListenerContainerFactory.
@Bean(name = "kafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(ConcurrentKafkaListenerContainerFactoryConfigurer configurer, ConsumerFactory<Object, Object> kafkaConsumerFactory) {
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
ContainerProperties containerProperties = factory.getContainerProperties();
containerProperties.setErrorHandler(new LocKafkaConsumerErrorHandler());
factory.setRecordFilterStrategy(locMessageFilterStrategy());
factory.setMessageConverter(recordMessageConverter());
configurer.configure(factory, kafkaConsumerFactory);
return factory;
}
use of org.springframework.kafka.listener.config.ContainerProperties in project loc-framework by lord-of-code.
the class LocKafkaTest method testConsumer.
@Test
@SuppressWarnings("unchecked")
public void testConsumer() throws Exception {
assertThat(concurrentKafkaListenerContainerFactory).isNotNull();
ContainerProperties containerProperties = concurrentKafkaListenerContainerFactory.getContainerProperties();
assertThat(containerProperties).isNotNull();
assertThat(containerProperties.getGenericErrorHandler()).isNotNull();
assertThat(containerProperties.getAckMode()).isEqualTo(AckMode.RECORD);
ConsumerFactory consumerFactory = concurrentKafkaListenerContainerFactory.getConsumerFactory();
assertThat(consumerFactory).isNotNull();
assertThat(consumerFactory.getConfigurationProperties()).isNotNull();
assertThat(consumerFactory.getConfigurationProperties()).isNotNull();
assertThat(consumerFactory.getConfigurationProperties().get("group.id")).isEqualTo("loc-kafka-unittest");
assertThat(consumerFactory.getConfigurationProperties().get("bootstrap.servers")).isEqualTo(Lists.newArrayList("127.0.0.1:9092"));
assertThat(consumerFactory.getConfigurationProperties().get("enable.auto.commit")).isEqualTo(false);
assertThat(consumerFactory.getConfigurationProperties().get("key.deserializer")).isEqualTo(org.apache.kafka.common.serialization.ByteArrayDeserializer.class);
assertThat(consumerFactory.getConfigurationProperties().get("value.deserializer")).isEqualTo(org.apache.kafka.common.serialization.ByteArrayDeserializer.class);
}
use of org.springframework.kafka.listener.config.ContainerProperties in project xm-ms-entity by xm-online.
the class ApplicationStartup method createSystemConsumer.
private void createSystemConsumer(String name, MessageListener<String, String> consumeEvent) {
log.info("Creating kafka consumer for topic {}", name);
ContainerProperties containerProps = new ContainerProperties(name);
Map<String, Object> props = kafkaProperties.buildConsumerProperties();
if (name.equals(applicationProperties.getKafkaSystemTopic())) {
props.put(ConsumerConfig.GROUP_ID_CONFIG, UUID.randomUUID().toString());
}
ConsumerFactory<String, String> factory = new DefaultKafkaConsumerFactory<>(props);
ConcurrentMessageListenerContainer<String, String> container = new ConcurrentMessageListenerContainer<>(factory, containerProps);
container.setupMessageListener(consumeEvent);
container.start();
log.info("Successfully created kafka consumer for topic {}", name);
}
use of org.springframework.kafka.listener.config.ContainerProperties in project eventapis by kloiasoft.
the class EventListenConfiguration method startOperations.
private void startOperations() {
Map<String, Object> consumerProperties = eventApisConfiguration.getEventBus().buildConsumerProperties();
DefaultKafkaConsumerFactory<String, Operation> operationConsumerFactory = new DefaultKafkaConsumerFactory<>(consumerProperties, new StringDeserializer(), new JsonDeserializer<>(Operation.class));
ContainerProperties operationContainerProperties = new ContainerProperties(Operation.OPERATION_EVENTS);
operationContainerProperties.setMessageListener(new MultipleEventMessageListener(eventMessageListeners));
operationListenerContainer = new ConcurrentMessageListenerContainer<>(operationConsumerFactory, operationContainerProperties);
operationListenerContainer.setBeanName("emon-operations");
operationListenerContainer.start();
}
use of org.springframework.kafka.listener.config.ContainerProperties in project spring-boot by spring-projects.
the class ConcurrentKafkaListenerContainerFactoryConfigurer method configure.
/**
* Configure the specified Kafka listener container factory. The factory can be
* further tuned and default settings can be overridden.
* @param listenerContainerFactory the {@link ConcurrentKafkaListenerContainerFactory}
* instance to configure
* @param consumerFactory the {@link ConsumerFactory} to use
*/
public void configure(ConcurrentKafkaListenerContainerFactory<Object, Object> listenerContainerFactory, ConsumerFactory<Object, Object> consumerFactory) {
listenerContainerFactory.setConsumerFactory(consumerFactory);
Listener container = this.properties.getListener();
ContainerProperties containerProperties = listenerContainerFactory.getContainerProperties();
if (container.getAckMode() != null) {
containerProperties.setAckMode(container.getAckMode());
}
if (container.getAckCount() != null) {
containerProperties.setAckCount(container.getAckCount());
}
if (container.getAckTime() != null) {
containerProperties.setAckTime(container.getAckTime());
}
if (container.getPollTimeout() != null) {
containerProperties.setPollTimeout(container.getPollTimeout());
}
if (container.getConcurrency() != null) {
listenerContainerFactory.setConcurrency(container.getConcurrency());
}
}
Aggregations