Ejemplo n.º 1
0
 public static void SaveEvent <T>(this IEventStoreClient eventStoreClient, string streamName, int expectedVersion, Guid eventId, T data)
 {
     eventStoreClient.SaveEvent(streamName,
                                expectedVersion,
                                eventId,
                                data.GetType().Name,
                                JsonConvert.SerializeObject(data));
 }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> CreateDeal(CreateDealCommand command)
        {
            //De-serialize - already done
            //Validate schema with DataAnnotations/XSD/JSONSchema
            //Apply command to domain
            //return response code;

            var streamName = StreamNames.DealStreamName(command.DealId);
            var eventId    = Guid.NewGuid(); //Is this correct? Or should it be cmd.DealId? Or something else?
            var payload    = JsonConvert.SerializeObject(command);
            await _eventStoreClient.SaveEvent(streamName, ExpectedVersion.NoStream, eventId, "DealCreated", payload);

            return(Ok());
        }
        private async Task ProcessNext()
        {
            //TODO: Allow cancellation
            var cmd = await _messageBusClient.Dequeue <CreateDealCommand>();

            //Run slow just for fun
            await Task.Delay(TimeSpan.FromSeconds(2));

            //Create the DealCreatedEvent in the new Deal-GUID stream.

            var streamName = StreamNames.DealStreamName(cmd.DealId);
            var eventId    = Guid.NewGuid(); //Is this correct? Or should it be cmd.DealId? Or something else?
            var payload    = cmd.ToJson();
            await _eventStoreClient.SaveEvent(streamName, ExpectedVersion.NoStream, eventId, "DealCreated", payload);

            //We will use Projections to merge them together.
        }