Java Code Examples for org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory#setRecordFilterStrategy()

The following examples show how to use org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory#setRecordFilterStrategy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonConfiguration.java    From grussell-spring-kafka with Apache License 2.0 6 votes vote down vote up
@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> retryKafkaListenerContainerFactory() {
	ConcurrentKafkaListenerContainerFactory<String, String> factory =
			new ConcurrentKafkaListenerContainerFactory<>();
	factory.setConsumerFactory(consumerFactory());
	factory.setRetryTemplate(new RetryTemplate());
	factory.setRecordFilterStrategy(new RecordFilterStrategy<String, String>() {

		@Override
		public boolean filter(ConsumerRecord<String, String> consumerRecord) {
			return consumerRecord.value().equals("bar");
		}

	});
	return factory;
}
 
Example 2
Source File: LocKafkaAutoConfiguration.java    From loc-framework with MIT License 5 votes vote down vote up
@Bean(name = "kafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
    ConcurrentKafkaListenerContainerFactoryConfigurer configurer,
    ConsumerFactory<Object, Object> kafkaConsumerFactory) {
  ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
  ContainerProperties containerProperties = factory.getContainerProperties();
  factory.setRecordFilterStrategy(locMessageFilterStrategy());
  factory.setErrorHandler(new LocKafkaConsumerErrorHandler());
  factory.setMessageConverter(recordMessageConverter());
  configurer.configure(factory, kafkaConsumerFactory);
  return factory;
}
 
Example 3
Source File: KafkaConsumerConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> filterKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = kafkaListenerContainerFactory("filter");
    factory.setRecordFilterStrategy(record -> record.value()
        .contains("World"));
    return factory;
}