Search in sources :

Example 1 with Operation

use of io.splitet.core.pojos.Operation in project eventapis by kloiasoft.

the class EventApisFactory method operationsKafkaListenerContainerFactory.

@Bean("operationsKafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<String, Operation> operationsKafkaListenerContainerFactory(ConsumerFactory<String, Operation> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, Operation> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    RetryTemplate retryTemplate = new RetryTemplate();
    factory.setRetryTemplate(retryTemplate);
    factory.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    scheduler.setBeanName("OperationsFactory-Scheduler");
    scheduler.initialize();
    factory.getContainerProperties().setScheduler(scheduler);
    ThreadPoolTaskScheduler consumerScheduler = new ThreadPoolTaskScheduler();
    consumerScheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    consumerScheduler.setBeanName("OperationsFactory-ConsumerScheduler");
    consumerScheduler.initialize();
    factory.getContainerProperties().setPollTimeout(3000L);
    factory.getContainerProperties().setAckOnError(false);
    factory.getContainerProperties().setConsumerTaskExecutor(consumerScheduler);
    factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.RECORD);
    /**
     * This is Fix for Spring Kafka versions which does not have ConsumerAwareErrorHandler handler till 2.0
     * When Listener faces with error, it retries snapshot operation
     * See https://github.com/kloiasoft/eventapis/issues/44
     */
    factory.getContainerProperties().setTransactionManager(new EmptyTransactionManager());
    // factory.getContainerProperties().setTransactionManager(platformTransactionManager);
    return factory;
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) ConcurrentKafkaListenerContainerFactory(org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory) Operation(io.splitet.core.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)

Example 2 with Operation

use of io.splitet.core.pojos.Operation in project eventapis by kloiasoft.

the class EventApisFactory method kafkaOperationsFactory.

@Bean
public ConsumerFactory<String, Operation> kafkaOperationsFactory() {
    KafkaProperties properties = eventApisConfiguration.getEventBus().clone();
    properties.getConsumer().setEnableAutoCommit(false);
    return new DefaultKafkaConsumerFactory<>(properties.buildConsumerProperties(), new StringDeserializer(), new JsonDeserializer<>(Operation.class, objectMapper));
}
Also used : KafkaProperties(io.splitet.core.kafka.KafkaProperties) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory) Operation(io.splitet.core.pojos.Operation) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with Operation

use of io.splitet.core.pojos.Operation in project eventapis by kloiasoft.

the class SpringKafkaOpListener method listenOperations.

@KafkaListener(topics = Operation.OPERATION_EVENTS, containerFactory = "operationsKafkaListenerContainerFactory")
void listenOperations(ConsumerRecord<String, Operation> record) throws EventStoreException {
    String key = record.key();
    Operation value = record.value();
    log.debug("Trying Snapshot: " + key + " " + value);
    userContext.extractUserContext(value.getUserContext());
    aggregateListenerService.listenOperations(record);
}
Also used : Operation(io.splitet.core.pojos.Operation) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 4 with Operation

use of io.splitet.core.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(io.splitet.core.pojos.Operation)

Example 5 with Operation

use of io.splitet.core.pojos.Operation in project eventapis by kloiasoft.

the class KafkaOperationRepositoryFactory method createKafkaOperationRepository.

public KafkaOperationRepository createKafkaOperationRepository(ObjectMapper objectMapper) {
    KafkaProducer<String, Operation> operationsKafka = new KafkaProducer<>(kafkaProperties.buildProducerProperties(), new StringSerializer(), new JsonSerializer<>(objectMapper));
    KafkaProducer<String, PublishedEventWrapper> eventsKafka = new KafkaProducer<>(kafkaProperties.buildProducerProperties(), new StringSerializer(), new JsonSerializer<>(objectMapper));
    return new KafkaOperationRepository(operationContext, userContext, operationsKafka, eventsKafka, kafkaProperties.getConsumer().getGroupId());
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) Operation(io.splitet.core.pojos.Operation) StringSerializer(org.apache.kafka.common.serialization.StringSerializer)

Aggregations

Operation (io.splitet.core.pojos.Operation)7 Bean (org.springframework.context.annotation.Bean)3 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)2 DefaultKafkaConsumerFactory (org.springframework.kafka.core.DefaultKafkaConsumerFactory)2 MultipleEventMessageListener (io.splitet.core.api.emon.service.MultipleEventMessageListener)1 KafkaProperties (io.splitet.core.kafka.KafkaProperties)1 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 KafkaListener (org.springframework.kafka.annotation.KafkaListener)1 ConcurrentKafkaListenerContainerFactory (org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory)1 ConcurrentMessageListenerContainer (org.springframework.kafka.listener.ConcurrentMessageListenerContainer)1 ContainerProperties (org.springframework.kafka.listener.ContainerProperties)1 RetryTemplate (org.springframework.retry.support.RetryTemplate)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1