Search in sources :

Example 1 with DefaultKafkaConsumerFactory

use of org.springframework.kafka.core.DefaultKafkaConsumerFactory in project spring-integration-samples by spring-projects.

the class Application method addAnotherListenerForTopics.

public void addAnotherListenerForTopics(String... topics) {
    Map<String, Object> consumerProperties = kafkaProperties.buildConsumerProperties();
    // change the group id so we don't revoke the other partitions.
    consumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, consumerProperties.get(ConsumerConfig.GROUP_ID_CONFIG) + "x");
    IntegrationFlow flow = IntegrationFlows.from(Kafka.messageDrivenChannelAdapter(new DefaultKafkaConsumerFactory<String, String>(consumerProperties), topics)).channel("fromKafka").get();
    this.flowContext.registration(flow).register();
}
Also used : IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Example 2 with DefaultKafkaConsumerFactory

use of org.springframework.kafka.core.DefaultKafkaConsumerFactory in project tutorials by eugenp.

the class KafkaConsumerConfig method greetingConsumerFactory.

public ConsumerFactory<String, Greeting> greetingConsumerFactory() {
    Map<String, Object> props = new HashMap<>();
    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
    props.put(ConsumerConfig.GROUP_ID_CONFIG, "greeting");
    return new DefaultKafkaConsumerFactory<>(props, new StringDeserializer(), new JsonDeserializer<>(Greeting.class));
}
Also used : HashMap(java.util.HashMap) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Example 3 with DefaultKafkaConsumerFactory

use of org.springframework.kafka.core.DefaultKafkaConsumerFactory in project spring-integration-samples by spring-projects.

the class Application method addAnotherListenerForTopics.

public void addAnotherListenerForTopics(String... topics) {
    Map<String, Object> consumerProperties = kafkaProperties.buildConsumerProperties();
    // change the group id so we don't revoke the other partitions.
    consumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, consumerProperties.get(ConsumerConfig.GROUP_ID_CONFIG) + "x");
    IntegrationFlow flow = IntegrationFlows.from(Kafka.messageDrivenChannelAdapter(new DefaultKafkaConsumerFactory<String, String>(consumerProperties), topics)).channel("fromKafka").get();
    this.flowContext.registration(flow).register();
}
Also used : IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Example 4 with DefaultKafkaConsumerFactory

use of org.springframework.kafka.core.DefaultKafkaConsumerFactory 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);
}
Also used : ContainerProperties(org.springframework.kafka.listener.config.ContainerProperties) ConcurrentMessageListenerContainer(org.springframework.kafka.listener.ConcurrentMessageListenerContainer) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Example 5 with DefaultKafkaConsumerFactory

use of org.springframework.kafka.core.DefaultKafkaConsumerFactory 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();
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) MultipleEventMessageListener(com.kloia.eventapis.api.emon.service.MultipleEventMessageListener) ContainerProperties(org.springframework.kafka.listener.config.ContainerProperties) Operation(com.kloia.eventapis.pojos.Operation) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Aggregations

DefaultKafkaConsumerFactory (org.springframework.kafka.core.DefaultKafkaConsumerFactory)6 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)3 ContainerProperties (org.springframework.kafka.listener.config.ContainerProperties)3 MultipleEventMessageListener (com.kloia.eventapis.api.emon.service.MultipleEventMessageListener)2 IntegrationFlow (org.springframework.integration.dsl.IntegrationFlow)2 PublishedEventWrapper (com.kloia.eventapis.kafka.PublishedEventWrapper)1 Operation (com.kloia.eventapis.pojos.Operation)1 HashMap (java.util.HashMap)1 ConcurrentMessageListenerContainer (org.springframework.kafka.listener.ConcurrentMessageListenerContainer)1