Search in sources :

Example 11 with EventKey

use of com.kloia.eventapis.common.EventKey in project eventapis by kloiasoft.

the class CreateStockCommandHandler method execute.

@RequestMapping(value = "/stock/create", method = RequestMethod.POST)
@Command
public EventKey execute(@RequestBody CreateStockCommandDto dto) throws Exception {
    StockCreatedEvent stockCreatedEvent = new StockCreatedEvent();
    BeanUtils.copyProperties(dto, stockCreatedEvent);
    EventKey eventKey = eventRepository.recordAndPublish(stockCreatedEvent);
    try {
        addStockCommandHandler.execute(eventKey.getEntityId(), new AddStockCommandDto(dto.getRemainingStock(), eventKey.getEntityId()));
    } catch (Exception e) {
        log.warn("Sub Command Failed:" + e.getMessage());
    }
    return eventKey;
}
Also used : StockCreatedEvent(com.kloia.sample.dto.event.StockCreatedEvent) AddStockCommandDto(com.kloia.sample.dto.command.AddStockCommandDto) EventKey(com.kloia.eventapis.common.EventKey) Command(com.kloia.eventapis.api.Command) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EventKey (com.kloia.eventapis.common.EventKey)11 DefaultConcurrencyResolver (com.kloia.eventapis.cassandra.DefaultConcurrencyResolver)5 EntityEvent (com.kloia.eventapis.cassandra.EntityEvent)5 EventStoreException (com.kloia.eventapis.exception.EventStoreException)5 Test (org.junit.Test)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 Views (com.kloia.eventapis.api.Views)4 Entity (com.kloia.eventapis.view.Entity)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 Command (com.kloia.eventapis.api.Command)2 IdCreationStrategy (com.kloia.eventapis.api.IdCreationStrategy)2 UUIDCreationStrategy (com.kloia.eventapis.api.impl.UUIDCreationStrategy)2 ConcurrencyResolver (com.kloia.eventapis.cassandra.ConcurrencyResolver)2 ConcurrentEventException (com.kloia.eventapis.cassandra.ConcurrentEventException)2 EventRecorder (com.kloia.eventapis.common.EventRecorder)2 EventType (com.kloia.eventapis.common.EventType)2 PublishedEvent (com.kloia.eventapis.common.PublishedEvent)2 IOperationRepository (com.kloia.eventapis.kafka.IOperationRepository)2 SerializableConsumer (com.kloia.eventapis.kafka.SerializableConsumer)2