Search in sources :

Example 1 with Operation

use of com.kloia.eventapis.pojos.Operation 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)

Example 2 with Operation

use of com.kloia.eventapis.pojos.Operation in project eventapis by kloiasoft.

the class SpringKafkaOpListener method listenOperations.

@Transactional(rollbackFor = Exception.class)
@KafkaListener(id = "op-listener", topics = Operation.OPERATION_EVENTS, containerFactory = "operationsKafkaListenerContainerFactory")
void listenOperations(ConsumerRecord<String, Operation> record) {
    String key = record.key();
    Operation value = record.value();
    log.debug("Incoming Message: " + key + " " + value);
    userContext.extractUserContext(value.getUserContext());
    for (AggregateListener snapshotRecorder : aggregateListeners) {
        snapshotRecorder.listenOperations(record);
    }
}
Also used : Operation(com.kloia.eventapis.pojos.Operation) AggregateListener(com.kloia.eventapis.view.AggregateListener) KafkaListener(org.springframework.kafka.annotation.KafkaListener) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Operation

use of com.kloia.eventapis.pojos.Operation in project eventapis by kloiasoft.

the class KafkaOperationRepository method failOperation.

/*    private KafkaTemplate<UUID,Operation> operationsKafka;
    private KafkaTemplate<UUID,PublishedEventWrapper> eventsKafka;

    @Autowired
    public KafkaOperationRepository(@Qualifier("operationsKafka") KafkaTemplate<UUID,Operation> operationsKafka,
                                    @Qualifier("eventsKafka") KafkaTemplate<UUID,PublishedEventWrapper> eventsKafka) {
        this.eventsKafka = eventsKafka;
        this.operationsKafka = operationsKafka;
    }*/
@Override
public void failOperation(String eventId, SerializableConsumer<Event> action) {
    Operation operation = new Operation();
    operation.setSender(senderGroupId);
    operation.setAggregateId(eventId);
    operation.setUserContext(userContext.getUserContext());
    operation.setContext(operationContext.getContext());
    operation.setTransactionState(TransactionState.TXN_FAILED);
    operation.setOpDate(System.currentTimeMillis());
    log.debug("Publishing Operation:" + operation.toString());
    operationsKafka.send(new ProducerRecord<>(Operation.OPERATION_EVENTS, operationContext.getContext().getOpId(), operation));
}
Also used : Operation(com.kloia.eventapis.pojos.Operation)

Example 4 with Operation

use of com.kloia.eventapis.pojos.Operation in project eventapis by kloiasoft.

the class KafkaOperationRepositoryFactory method createOperationConsumer.

public Consumer<String, Operation> createOperationConsumer(ObjectMapper objectMapper) {
    KafkaProperties properties = kafkaProperties.clone();
    properties.getConsumer().setEnableAutoCommit(false);
    return new KafkaConsumer<>(properties.buildConsumerProperties(), new StringDeserializer(), new JsonDeserializer<>(Operation.class, objectMapper));
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) Operation(com.kloia.eventapis.pojos.Operation)

Example 5 with Operation

use of com.kloia.eventapis.pojos.Operation in project eventapis by kloiasoft.

the class EventApisFactory method operationsKafkaListenerContainerFactory.

@Bean("operationsKafkaListenerContainerFactory")
public KafkaListenerContainerFactory<KafkaMessageListenerContainer<String, Operation>> operationsKafkaListenerContainerFactory(ConsumerFactory<String, Operation> consumerFactory, PlatformTransactionManager platformTransactionManager) {
    AbstractKafkaListenerContainerFactory<KafkaMessageListenerContainer<String, Operation>, String, Operation> abstractKafkaListenerContainerFactory = new EventApisKafkaListenerContainerFactory(consumerFactory);
    RetryTemplate retryTemplate = new RetryTemplate();
    abstractKafkaListenerContainerFactory.setRetryTemplate(retryTemplate);
    abstractKafkaListenerContainerFactory.getContainerProperties().setPollTimeout(3000L);
    abstractKafkaListenerContainerFactory.getContainerProperties().setAckOnError(false);
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    scheduler.setBeanName("OperationsFactory-Scheduler");
    scheduler.initialize();
    abstractKafkaListenerContainerFactory.getContainerProperties().setScheduler(scheduler);
    // ThreadPoolTaskScheduler consumerScheduler = new ThreadPoolTaskScheduler();
    // consumerScheduler.setPoolSize(30);
    // consumerScheduler.setBeanName("OperationsFactory-ConsumerScheduler");
    // consumerScheduler.initialize();
    // 
    // abstractKafkaListenerContainerFactory.getContainerProperties().setConsumerTaskExecutor(consumerScheduler);
    abstractKafkaListenerContainerFactory.getContainerProperties().setAckMode(AbstractMessageListenerContainer.AckMode.RECORD);
    abstractKafkaListenerContainerFactory.getContainerProperties().setTransactionManager(platformTransactionManager);
    return abstractKafkaListenerContainerFactory;
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) KafkaMessageListenerContainer(org.springframework.kafka.listener.KafkaMessageListenerContainer) Operation(com.kloia.eventapis.pojos.Operation) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Operation (com.kloia.eventapis.pojos.Operation)7 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)2 MultipleEventMessageListener (com.kloia.eventapis.api.emon.service.MultipleEventMessageListener)1 AggregateListener (com.kloia.eventapis.view.AggregateListener)1 KafkaConsumer (org.apache.kafka.clients.consumer.KafkaConsumer)1 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 Bean (org.springframework.context.annotation.Bean)1 KafkaListener (org.springframework.kafka.annotation.KafkaListener)1 DefaultKafkaConsumerFactory (org.springframework.kafka.core.DefaultKafkaConsumerFactory)1 KafkaMessageListenerContainer (org.springframework.kafka.listener.KafkaMessageListenerContainer)1 ContainerProperties (org.springframework.kafka.listener.config.ContainerProperties)1 RetryTemplate (org.springframework.retry.support.RetryTemplate)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1 Transactional (org.springframework.transaction.annotation.Transactional)1