use of org.springframework.kafka.annotation.KafkaListener in project eventapis by kloiasoft.
the class StockReservedEventHandler method execute.
@Override
@KafkaListener(topics = "StockReservedEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(StockReservedEvent dto) throws EventStoreException, ConcurrentEventException {
Orders order = orderQuery.queryEntity(dto.getOrderId());
if (order.getState() == OrderState.RESERVING_STOCK) {
PaymentProcessEvent paymentProcessEvent = new PaymentProcessEvent(order.getId(), dto.getSender().getVersion(), new PaymentInformation(order.getPaymentAddress(), order.getAmount(), order.getCardInformation()));
log.info("Payment is processing : " + dto);
return eventRepository.recordAndPublish(order, paymentProcessEvent);
} else
throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
use of org.springframework.kafka.annotation.KafkaListener in project eventapis by kloiasoft.
the class DoPaymentEventHandler method execute.
@KafkaListener(topics = "PaymentProcessEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(PaymentProcessEvent dto) throws EventStoreException, EventPulisherException, ConcurrentEventException {
PaymentSuccessEvent paymentSuccessEvent = new PaymentSuccessEvent();
BeanUtils.copyProperties(dto.getPaymentInformation(), paymentSuccessEvent);
paymentSuccessEvent.setOrderId(dto.getSender().getEntityId());
if (dto.getPaymentInformation().getAmount() > 2000)
throw new RuntimeException("Bla Bla");
if (dto.getPaymentInformation().getAmount() > 1000) {
PaymentFailedEvent paymentFailedEvent = new PaymentFailedEvent();
BeanUtils.copyProperties(dto.getPaymentInformation(), paymentFailedEvent);
paymentFailedEvent.setOrderId(dto.getSender().getEntityId());
return eventRepository.recordAndPublish(paymentFailedEvent);
}
return eventRepository.recordAndPublish(paymentSuccessEvent);
}
use of org.springframework.kafka.annotation.KafkaListener in project eventapis by kloiasoft.
the class WaitingStockReleaseEventHandler method execute.
@Override
@KafkaListener(topics = "WaitingStockReleaseEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(WaitingStockReleaseEvent dto) throws Exception {
Stock stock = stockQuery.queryEntity(dto.getStockId());
StockReservedEvent stockReservedEvent = stockQuery.queryEventData(dto.getStockId(), dto.getReservedStockVersion());
return eventRepository.recordAndPublish(stock, new StockReleasedEvent(dto.getSender().getEntityId(), stockReservedEvent.getNumberOfItemsSold()), entityEvent -> new StockConcurrencyResolver());
}
Aggregations