org.springframework.kafka.listener.ConcurrentMessageListenerContainer Java Examples
The following examples show how to use
org.springframework.kafka.listener.ConcurrentMessageListenerContainer.
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: KafkaConfiguration.java From ad with Apache License 2.0 | 6 votes |
@Bean KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> containerFactory = new ConcurrentKafkaListenerContainerFactory<>(); containerFactory.setConcurrency(concurrency); Map<String, Object> config = Maps.newHashMap(); config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); // 由于课程原版实现中广告的索引数据是存在于ConcurrentHashMap中, 即每个索引服务实例的jvm中。 // 所以当每一个索引实例监听kafka topic数据时, 需要保证每个实例都处于不同的消费者组 // 即各个实例之间需要各不相同的groupId, 保证在部署多实例时, 每个实例都可以加载到完整的索引数据 // 但在本实现中由于将索引数据单独提出, 存放到了Redis数据库中, 所以应该让所有实例属于同一个消费者组 // 共同消费kafka topic下的数据, 保证索引数据不会被重复消费。 // 综上, 若索引数据的存放如果为各个实例自身的jvm, 应该考虑加上以下代码(或自行编写其他实现)保证各实例处于不同的消费者组 // 若索引数据存放的位置, 是所有检索实例共享的位置, 应该将以下配置取消(或直接删除本类) config.put(ConsumerConfig.GROUP_ID_CONFIG, UUID.randomUUID().toString()); DefaultKafkaConsumerFactory<String, String> consumerFactory = new DefaultKafkaConsumerFactory<String, String>(config); containerFactory.setConsumerFactory(consumerFactory); return containerFactory; }
Example #2
Source File: KafkaConsumerConfig.java From stateful-functions with Apache License 2.0 | 6 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory(ConsumerFactory<String, String> consumerFactory) { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory); return factory; }
Example #3
Source File: KafkaConsumerConfiguration.java From ZTuoExchange_framework with MIT License | 6 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(concurrency); factory.getContainerProperties().setPollTimeout(1500); factory.setBatchListener(true); return factory; }
Example #4
Source File: KafkaConsumerConfig.java From MicroCommunity with Apache License 2.0 | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<String, String>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(concurrency); factory.getContainerProperties().setPollTimeout(1500); return factory; }
Example #5
Source File: AConsumerConfig.java From SO with BSD 2-Clause "Simplified" License | 5 votes |
/** * return KafkaListenerContainerFactory.<BR/> * * @return KafkaListenerContainerFactory */ @Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { log.debug("kafkaListenerContainerFactory()"); ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(Settings2.HANDLER_COUNT); factory.getContainerProperties().setPollTimeout(Settings2.getPollTimeout()); return factory; }
Example #6
Source File: ReceiverConfig.java From spring-kafka with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); return factory; }
Example #7
Source File: ConsumingChannelConfig.java From spring-kafka with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Bean public ConcurrentMessageListenerContainer<String, String> kafkaListenerContainer() { ContainerProperties containerProps = new ContainerProperties(springIntegrationKafkaTopic); return (ConcurrentMessageListenerContainer<String, String>) new ConcurrentMessageListenerContainer<>( consumerFactory(), containerProps); }
Example #8
Source File: ReceiverConfig.java From spring-kafka with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); return factory; }
Example #9
Source File: KafkaBinderTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
private KafkaConsumer getKafkaConsumer(Binding binding) { DirectFieldAccessor bindingAccessor = new DirectFieldAccessor(binding); KafkaMessageDrivenChannelAdapter adapter = (KafkaMessageDrivenChannelAdapter) bindingAccessor .getPropertyValue("lifecycle"); DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); ConcurrentMessageListenerContainer messageListenerContainer = (ConcurrentMessageListenerContainer) adapterAccessor .getPropertyValue("messageListenerContainer"); DirectFieldAccessor containerAccessor = new DirectFieldAccessor( messageListenerContainer); DefaultKafkaConsumerFactory consumerFactory = (DefaultKafkaConsumerFactory) containerAccessor .getPropertyValue("consumerFactory"); return (KafkaConsumer) consumerFactory.createConsumer(); }
Example #10
Source File: AConsumerConfig.java From SO with BSD 2-Clause "Simplified" License | 5 votes |
/** * return KafkaListenerContainerFactory.<BR/> * * @return KafkaListenerContainerFactory */ @Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { log.debug("kafkaListenerContainerFactory()"); ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(Settings2.HANDLER_COUNT); factory.getContainerProperties().setPollTimeout(Settings2.getPollTimeout()); return factory; }
Example #11
Source File: KafkaConfig.java From gae with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(3); factory.getContainerProperties().setPollTimeout(3000); return factory; }
Example #12
Source File: KafkaConsumerConfig.java From springboot_cwenao with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<String, String>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(4); factory.getContainerProperties().setPollTimeout(4000); return factory; }
Example #13
Source File: ProductConsumerConfiguration.java From integration-patterns with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE); return factory; }
Example #14
Source File: KafkaConsumerConfig.java From javatech with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
@Bean(name = "kafkaListenerContainerFactory1") public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory1() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory("groupB")); factory.setConcurrency(3); factory.getContainerProperties().setPollTimeout(3000); return factory; }
Example #15
Source File: KafkaConsumerConfig.java From javatech with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
@Bean(name = "kafkaListenerContainerFactory") public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory("groupA")); factory.setConcurrency(3); factory.getContainerProperties().setPollTimeout(3000); return factory; }
Example #16
Source File: KafkaConsumerConfiguration.java From ZTuoExchange_framework with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(concurrency); factory.getContainerProperties().setPollTimeout(1500); factory.setBatchListener(true); return factory; }
Example #17
Source File: KafkaConsumerConfig.java From kafka-with-springboot with Apache License 2.0 | 5 votes |
@Bean(name = "kafkaListenerContainerFactoryForBatchConsumer") public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactoryForBatchConsumer() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConcurrency(1); factory.setBatchListener(true); factory.setConsumerFactory(consumerFactory()); return factory; }
Example #18
Source File: KafkaConsumerConfig.java From kafka-with-springboot with Apache License 2.0 | 5 votes |
@Bean(name = "kafkaListenerContainerFactoryWith6Consumer") public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactoryWith3Consumer() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConcurrency(6); //3 partition -> 6 thread in parallel in a single consumer factory.setConsumerFactory(consumerFactory()); return factory; }
Example #19
Source File: KafkaConsumerConfig.java From kafka-with-springboot with Apache License 2.0 | 5 votes |
@Bean @Primary public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); return factory; }
Example #20
Source File: KafkaConsumerConfig.java From flink-statefun with Apache License 2.0 | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory(ConsumerFactory<String, String> consumerFactory) { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory); return factory; }
Example #21
Source File: KafkaConsumerConfiguration.java From ZTuoExchange_framework with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(concurrency); factory.getContainerProperties().setPollTimeout(1500); factory.setBatchListener(true); return factory; }
Example #22
Source File: KafkaConsumerConfig.java From ext-opensource-netty with Mozilla Public License 2.0 | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.getContainerProperties().setPollTimeout(1500); return factory; }
Example #23
Source File: KafkaConsumerConfiguration.java From ZTuoExchange_framework with MIT License | 5 votes |
@Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(concurrency); factory.getContainerProperties().setPollTimeout(1500); factory.setBatchListener(true); return factory; }