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