Search in sources :

Example 11 with KafkaListener

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);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) PaymentProcessEvent(com.kloia.sample.dto.event.PaymentProcessEvent) PaymentInformation(com.kloia.sample.model.PaymentInformation) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 12 with KafkaListener

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);
}
Also used : PaymentSuccessEvent(com.kloia.sample.dto.event.PaymentSuccessEvent) PaymentFailedEvent(com.kloia.sample.dto.event.PaymentFailedEvent) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 13 with KafkaListener

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());
}
Also used : StockReleasedEvent(com.kloia.sample.dto.event.StockReleasedEvent) StockReservedEvent(com.kloia.sample.dto.event.StockReservedEvent) Stock(com.kloia.sample.model.Stock) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Aggregations

KafkaListener (org.springframework.kafka.annotation.KafkaListener)13 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)3 EventStoreException (com.kloia.eventapis.exception.EventStoreException)3 IOException (java.io.IOException)3 Message (org.openkilda.messaging.Message)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 StockReservedEvent (com.kloia.sample.dto.event.StockReservedEvent)2 Orders (com.kloia.sample.model.Orders)2 Stock (com.kloia.sample.model.Stock)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 ClubServiceMsgDispatch (com.code.server.login.service.ClubServiceMsgDispatch)1 UserServiceMsgDispatch (com.code.server.login.service.UserServiceMsgDispatch)1 JsonObject (com.google.gson.JsonObject)1 EventKey (com.kloia.eventapis.common.EventKey)1 Operation (com.kloia.eventapis.pojos.Operation)1 AggregateListener (com.kloia.eventapis.view.AggregateListener)1 StockNotEnoughException (com.kloia.sample.dto.StockNotEnoughException)1 ReturnPaymentCommandDto (com.kloia.sample.dto.command.ReturnPaymentCommandDto)1 OrderCancelledEvent (com.kloia.sample.dto.event.OrderCancelledEvent)1 PaymentFailedEvent (com.kloia.sample.dto.event.PaymentFailedEvent)1