use of org.springframework.kafka.listener.ContainerProperties in project core-services by digit-egov.
the class PersisterConsumerConfig method container.
@Bean
public KafkaMessageListenerContainer<String, String> container() throws Exception {
ContainerProperties properties = new ContainerProperties(this.topics.toArray(new String[topics.size()]));
// set more properties
// properties.setPauseEnabled(true);
// properties.setPauseAfter(0);
// properties.setGenericErrorHandler(kafkaConsumerErrorHandler);
properties.setMessageListener(indexerMessageListener);
log.info("Custom KafkaListenerContainer built...");
return new KafkaMessageListenerContainer<>(consumerFactory(), properties);
}
use of org.springframework.kafka.listener.ContainerProperties in project chutney by chutney-testing.
the class KafkaBasicConsumeTask method createMessageListenerContainer.
private ConcurrentMessageListenerContainer<String, String> createMessageListenerContainer(MessageListener<String, String> messageListener) {
ContainerProperties containerProperties = new ContainerProperties(topic);
containerProperties.setMessageListener(messageListener);
containerProperties.setAckMode(ContainerProperties.AckMode.valueOf(this.ackMode));
ofNullable(properties.get(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG)).ifPresent(acims -> containerProperties.setAckTime(Long.parseLong(acims)));
ofNullable(properties.get(AUTO_COMMIT_COUNT_CONFIG)).ifPresent(acc -> containerProperties.setAckCount(Integer.parseInt(acc)));
return new ConcurrentMessageListenerContainer<>(kafkaConsumerFactoryFactory.create(target, group, properties), containerProperties);
}
use of org.springframework.kafka.listener.ContainerProperties in project chutney by chutney-testing.
the class KafkaBasicConsumeTaskTest method overrideTaskMessageListenerContainer.
private MessageListener<String, String> overrideTaskMessageListenerContainer(Task task) {
ConsumerFactory<String, String> cf = mock(ConsumerFactory.class, RETURNS_DEEP_STUBS);
Consumer<String, String> consumer = mock(Consumer.class);
given(cf.createConsumer(any(), any(), any(), any())).willReturn(consumer);
when(cf.getConfigurationProperties().get(eq(ConsumerConfig.GROUP_ID_CONFIG))).thenReturn(GROUP);
KafkaConsumerFactoryFactory kafkaConsumerFactoryFactory = mock(KafkaConsumerFactoryFactory.class);
when(kafkaConsumerFactoryFactory.create(any(), any(), any())).thenReturn(cf);
ReflectionTestUtils.setField(task, "kafkaConsumerFactoryFactory", kafkaConsumerFactoryFactory);
ContainerProperties containerProperties = new ContainerProperties(TOPIC);
containerProperties.setGroupId(GROUP);
containerProperties.setMessageListener(ReflectionTestUtils.invokeMethod(task, "createMessageListener"));
ConcurrentMessageListenerContainer<String, String> messageListenerContainer = new ConcurrentMessageListenerContainer<>(cf, containerProperties);
return (MessageListener<String, String>) messageListenerContainer.getContainerProperties().getMessageListener();
}
use of org.springframework.kafka.listener.ContainerProperties in project spring-boot by spring-projects.
the class KafkaAutoConfigurationTests method listenerProperties.
@SuppressWarnings("unchecked")
@Test
void listenerProperties() {
this.contextRunner.withPropertyValues("spring.kafka.template.default-topic=testTopic", "spring.kafka.template.transaction-id-prefix=txOverride", "spring.kafka.listener.ack-mode=MANUAL", "spring.kafka.listener.client-id=client", "spring.kafka.listener.ack-count=123", "spring.kafka.listener.ack-time=456", "spring.kafka.listener.concurrency=3", "spring.kafka.listener.poll-timeout=2000", "spring.kafka.listener.no-poll-threshold=2.5", "spring.kafka.listener.type=batch", "spring.kafka.listener.idle-between-polls=1s", "spring.kafka.listener.idle-event-interval=1s", "spring.kafka.listener.idle-partition-event-interval=1s", "spring.kafka.listener.monitor-interval=45", "spring.kafka.listener.log-container-config=true", "spring.kafka.listener.missing-topics-fatal=true", "spring.kafka.jaas.enabled=true", "spring.kafka.listener.immediate-stop=true", "spring.kafka.producer.transaction-id-prefix=foo", "spring.kafka.jaas.login-module=foo", "spring.kafka.jaas.control-flag=REQUISITE", "spring.kafka.jaas.options.useKeyTab=true", "spring.kafka.listener.async-acks=true").run((context) -> {
DefaultKafkaProducerFactory<?, ?> producerFactory = context.getBean(DefaultKafkaProducerFactory.class);
DefaultKafkaConsumerFactory<?, ?> consumerFactory = context.getBean(DefaultKafkaConsumerFactory.class);
KafkaTemplate<?, ?> kafkaTemplate = context.getBean(KafkaTemplate.class);
AbstractKafkaListenerContainerFactory<?, ?, ?> kafkaListenerContainerFactory = (AbstractKafkaListenerContainerFactory<?, ?, ?>) context.getBean(KafkaListenerContainerFactory.class);
assertThat(kafkaTemplate.getMessageConverter()).isInstanceOf(MessagingMessageConverter.class);
assertThat(kafkaTemplate).hasFieldOrPropertyWithValue("producerFactory", producerFactory);
assertThat(kafkaTemplate.getDefaultTopic()).isEqualTo("testTopic");
assertThat(kafkaTemplate).hasFieldOrPropertyWithValue("transactionIdPrefix", "txOverride");
assertThat(kafkaListenerContainerFactory.getConsumerFactory()).isEqualTo(consumerFactory);
ContainerProperties containerProperties = kafkaListenerContainerFactory.getContainerProperties();
assertThat(containerProperties.getAckMode()).isEqualTo(AckMode.MANUAL);
assertThat(containerProperties.isAsyncAcks()).isEqualTo(true);
assertThat(containerProperties.getClientId()).isEqualTo("client");
assertThat(containerProperties.getAckCount()).isEqualTo(123);
assertThat(containerProperties.getAckTime()).isEqualTo(456L);
assertThat(containerProperties.getPollTimeout()).isEqualTo(2000L);
assertThat(containerProperties.getNoPollThreshold()).isEqualTo(2.5f);
assertThat(containerProperties.getIdleBetweenPolls()).isEqualTo(1000L);
assertThat(containerProperties.getIdleEventInterval()).isEqualTo(1000L);
assertThat(containerProperties.getIdlePartitionEventInterval()).isEqualTo(1000L);
assertThat(containerProperties.getMonitorInterval()).isEqualTo(45);
assertThat(containerProperties.isLogContainerConfig()).isTrue();
assertThat(containerProperties.isMissingTopicsFatal()).isTrue();
assertThat(containerProperties.isStopImmediate()).isTrue();
assertThat(kafkaListenerContainerFactory).extracting("concurrency").isEqualTo(3);
assertThat(kafkaListenerContainerFactory.isBatchListener()).isTrue();
assertThat(context.getBeansOfType(KafkaJaasLoginModuleInitializer.class)).hasSize(1);
KafkaJaasLoginModuleInitializer jaas = context.getBean(KafkaJaasLoginModuleInitializer.class);
assertThat(jaas).hasFieldOrPropertyWithValue("loginModule", "foo");
assertThat(jaas).hasFieldOrPropertyWithValue("controlFlag", AppConfigurationEntry.LoginModuleControlFlag.REQUISITE);
assertThat(context.getBeansOfType(KafkaTransactionManager.class)).hasSize(1);
assertThat(((Map<String, String>) ReflectionTestUtils.getField(jaas, "options"))).containsExactly(entry("useKeyTab", "true"));
});
}
use of org.springframework.kafka.listener.ContainerProperties in project spring-boot by spring-projects.
the class KafkaPropertiesTests method listenerDefaultValuesAreConsistent.
@Test
void listenerDefaultValuesAreConsistent() {
ContainerProperties container = new ContainerProperties("test");
Listener listenerProperties = new KafkaProperties().getListener();
assertThat(listenerProperties.isMissingTopicsFatal()).isEqualTo(container.isMissingTopicsFatal());
}
Aggregations