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;
}
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));
}
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);
}
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));
}
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());
}
Aggregations