当前位置: 首页>>代码示例>>Java>>正文


Java ConsumerFactory类代码示例

本文整理汇总了Java中org.springframework.kafka.core.ConsumerFactory的典型用法代码示例。如果您正苦于以下问题:Java ConsumerFactory类的具体用法?Java ConsumerFactory怎么用?Java ConsumerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConsumerFactory类属于org.springframework.kafka.core包,在下文中一共展示了ConsumerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSystemConsumer

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
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);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:17,代码来源:ApplicationStartup.java

示例2: messageListenerContainer

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean
public MessageListenerContainer messageListenerContainer(
        ConsumerFactory<String, DefaultAvMessage> consumerFactory,
        MessageListener<String, AvMessage> messageListener,
        ThreadPoolTaskScheduler kafkaClientThreadPoolTaskScheduler
) {
    ContainerProperties props = new ContainerProperties(resultTopic);
    // shouldn't be necessary but the default scheduler is not destroyed after shutdown
    props.setScheduler(kafkaClientThreadPoolTaskScheduler);

    MessageListenerContainer container = new ConcurrentMessageListenerContainer<>(
            consumerFactory,
            props
    );
    container.setupMessageListener(messageListener);

    return container;
}
 
开发者ID:dvoraka,项目名称:av-service,代码行数:19,代码来源:KafkaFileClientConfig.java

示例3: consumerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
public ConsumerFactory<String, String> consumerFactory() {

        Map<String, Object> properties = new HashMap<String, Object>();

        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, brokers);
        properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
        properties.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "100");
        properties.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "15000");
        properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        properties.put(ConsumerConfig.GROUP_ID_CONFIG, group);
        properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");

        return new DefaultKafkaConsumerFactory<String, String>(properties);

    }
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:17,代码来源:KafkaConsumerConfig.java

示例4: createConsumerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
private ConsumerFactory<?, ?> createConsumerFactory(String group) {
	if (defaultConsumerFactory != null) {
		return defaultConsumerFactory;
	}
	Map<String, Object> props = new HashMap<>();
	props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);
	props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);
	if (!ObjectUtils.isEmpty(binderConfigurationProperties.getConsumerConfiguration())) {
		props.putAll(binderConfigurationProperties.getConsumerConfiguration());
	}
	if (!props.containsKey(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG)) {
		props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
				this.binderConfigurationProperties.getKafkaConnectionString());
	}
	props.put("group.id", group);
	return new DefaultKafkaConsumerFactory<>(props);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:18,代码来源:KafkaBinderMetrics.java

示例5: createKafkaConsumerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
private ConsumerFactory<?, ?> createKafkaConsumerFactory(boolean anonymous, String consumerGroup,
		ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties) {
	Map<String, Object> props = new HashMap<>();
	props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);
	props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);
	props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
	props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, 100);
	props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, anonymous ? "latest" : "earliest");
	props.put(ConsumerConfig.GROUP_ID_CONFIG, consumerGroup);

	if (!ObjectUtils.isEmpty(configurationProperties.getConsumerConfiguration())) {
		props.putAll(configurationProperties.getConsumerConfiguration());
	}
	if (ObjectUtils.isEmpty(props.get(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG))) {
		props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, this.configurationProperties.getKafkaConnectionString());
	}
	if (!ObjectUtils.isEmpty(consumerProperties.getExtension().getConfiguration())) {
		props.putAll(consumerProperties.getExtension().getConfiguration());
	}
	if (!ObjectUtils.isEmpty(consumerProperties.getExtension().getStartOffset())) {
		props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
				consumerProperties.getExtension().getStartOffset().name());
	}

	return new DefaultKafkaConsumerFactory<>(props);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:27,代码来源:KafkaMessageChannelBinder.java

示例6: healthIndicator

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean
KafkaBinderHealthIndicator healthIndicator(KafkaMessageChannelBinder kafkaMessageChannelBinder) {
	Map<String, Object> props = new HashMap<>();
	props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);
	props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class);
	if (!ObjectUtils.isEmpty(configurationProperties.getConsumerConfiguration())) {
		props.putAll(configurationProperties.getConsumerConfiguration());
	}
	if (!props.containsKey(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG)) {
		props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, this.configurationProperties.getKafkaConnectionString());
	}
	ConsumerFactory<?, ?> consumerFactory = new DefaultKafkaConsumerFactory<>(props);
	KafkaBinderHealthIndicator indicator = new KafkaBinderHealthIndicator(kafkaMessageChannelBinder,
			consumerFactory);
	indicator.setTimeout(this.configurationProperties.getHealthTimeout());
	return indicator;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:18,代码来源:KafkaBinderConfiguration.java

示例7: testKafkaHealthIndicatorProperties

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Test
public void testKafkaHealthIndicatorProperties() {
	assertNotNull(this.kafkaBinderHealthIndicator);
	Field consumerFactoryField = ReflectionUtils.findField(KafkaBinderHealthIndicator.class, "consumerFactory",
			ConsumerFactory.class);
	ReflectionUtils.makeAccessible(consumerFactoryField);
	DefaultKafkaConsumerFactory consumerFactory = (DefaultKafkaConsumerFactory) ReflectionUtils.getField(
			consumerFactoryField, this.kafkaBinderHealthIndicator);
	Field configField = ReflectionUtils.findField(DefaultKafkaConsumerFactory.class, "configs", Map.class);
	ReflectionUtils.makeAccessible(configField);
	Map<String, Object> configs = (Map<String, Object>) ReflectionUtils.getField(configField, consumerFactory);
	assertTrue(configs.containsKey("bootstrap.servers"));
	List<String> bootstrapServers = new ArrayList<>();
	bootstrapServers.add("10.98.09.199:9092");
	bootstrapServers.add("10.98.09.196:9092");
	assertTrue(((List<String>) configs.get("bootstrap.servers")).containsAll(bootstrapServers));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:18,代码来源:KafkaBinderAutoConfigurationPropertiesTest.java

示例8: fileServerMessageListenerContainer

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean
public MessageListenerContainer fileServerMessageListenerContainer(
        ConsumerFactory<String, DefaultAvMessage> consumerFactory,
        MessageListener<String, AvMessage> fileServerMessageListener,
        ThreadPoolTaskScheduler kafkaServerThreadPoolTaskScheduler
) {
    ContainerProperties props = new ContainerProperties(fileTopic);
    // shouldn't be necessary but the default scheduler is not destroyed after shutdown
    props.setScheduler(kafkaServerThreadPoolTaskScheduler);

    MessageListenerContainer container = new ConcurrentMessageListenerContainer<>(
            consumerFactory,
            props
    );
    container.setupMessageListener(fileServerMessageListener);

    return container;
}
 
开发者ID:dvoraka,项目名称:av-service,代码行数:19,代码来源:KafkaServerConfig.java

示例9: consumerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean
public ConsumerFactory<Integer, String> consumerFactory() {
  final Map<String, Object> consumerProps = KafkaTestUtils
      .consumerProps("sampleRawConsumer", "false", embeddedKafka);
  consumerProps.put("auto.offset.reset", "earliest");

  return new TracingConsumerFactory<>(new DefaultKafkaConsumerFactory<>(consumerProps), tracer());
}
 
开发者ID:opentracing-contrib,项目名称:java-kafka-client,代码行数:9,代码来源:TestConfiguration.java

示例10: consumerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
public ConsumerFactory<String, String> consumerFactory(String groupId) {
    Map<String, Object> props = new HashMap<>();
    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
    props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
    props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
    props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
    return new DefaultKafkaConsumerFactory<>(props);
}
 
开发者ID:ebi-wp,项目名称:kafka-streams-api-websockets,代码行数:9,代码来源:KafkaConsumerConfig.java

示例11: consumerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
/**
 * Create the consumers by loading the config
 * 
 * @return
 */
@Bean
public ConsumerFactory<String, Student> consumerFactory() {

	return new DefaultKafkaConsumerFactory<>(consumerConfigs(),
			new StringDeserializer(), new JsonDeserializer<>(
					Student.class));
}
 
开发者ID:sarojrout,项目名称:spring-tutorial,代码行数:13,代码来源:StudentConsumerConfig.java

示例12: kafkaConsumerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean
public ConsumerFactory<String, PublishedEventWrapper> kafkaConsumerFactory(KafkaOperationRepositoryFactory kafkaOperationRepositoryFactory) {
    return new ConsumerFactory<String, PublishedEventWrapper>() {
        @Override
        public Consumer<String, PublishedEventWrapper> createConsumer() {
            return kafkaOperationRepositoryFactory.createEventConsumer(objectMapper);
        }

        @Override
        public boolean isAutoCommit() {
            return kafkaOperationRepositoryFactory.isAutoCommit();
        }
    };
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:15,代码来源:EventApisFactory.java

示例13: kafkaOperationsFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean
public ConsumerFactory<String,Operation> kafkaOperationsFactory(KafkaOperationRepositoryFactory kafkaOperationRepositoryFactory) {
    return new ConsumerFactory<String, Operation>() {
        @Override
        public Consumer<String, Operation> createConsumer() {
            return kafkaOperationRepositoryFactory.createOperationConsumer(objectMapper);
        }

        @Override
        public boolean isAutoCommit() {
            return kafkaOperationRepositoryFactory.isAutoCommit();
        }
    };
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:15,代码来源:EventApisFactory.java

示例14: eventsKafkaListenerContainerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean({"eventsKafkaListenerContainerFactory", "kafkaListenerContainerFactory"})
public ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> eventsKafkaListenerContainerFactory(
        EventApisConfiguration eventApisConfiguration,EventMessageConverter eventMessageConverter, ConsumerFactory<String,PublishedEventWrapper> consumerFactory) {

    ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    factory.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getEventConcurrency());
    factory.setMessageConverter(eventMessageConverter);
    factory.getContainerProperties().setPollTimeout(3000);
    return factory;
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:12,代码来源:EventApisFactory.java

示例15: operationsKafkaListenerContainerFactory

import org.springframework.kafka.core.ConsumerFactory; //导入依赖的package包/类
@Bean("operationsKafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<String, Operation> operationsKafkaListenerContainerFactory(
        EventApisConfiguration eventApisConfiguration,ConsumerFactory<String,Operation> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, Operation> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    factory.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getOperationConcurrency());
    factory.getContainerProperties().setPollTimeout(3000);
    return factory;
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:10,代码来源:EventApisFactory.java


注:本文中的org.springframework.kafka.core.ConsumerFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。