Beispiel #1
0
        public async Task PublishAsync <TEvent>(TEvent @event) where TEvent : IEvent
        {
            using (var context = _dbContextFactory.Create())
            {
                await context.Events.AddAsync(_eventModelFactory.Create(@event));

                await context.SaveChangesAsync();
            }

            await _eventBusPublisher.PublishAsync(@event);
        }
Beispiel #2
0
        public async Task <ICommandResult <CarModel> > Handle(CreateCarCommand request, CancellationToken cancellationToken)
        {
            var validator = _validatorFactory.Create <CreateCarCommand, CreateCarCommandValidator>();

            await ValidateAsync(request, validator);

            var domainObj    = _mapper.Map <Car>(request.Payload);
            var newDomainObj = Car.CreateNewCar(domainObj.Brand, domainObj.Model, domainObj.Year);
            var success      = await _commandCarCatalogRepository.CreateCarAsync(request.Name, newDomainObj);

            if (success)
            {
                Log.Information("CreateCarCommand successfully created");
                var createCarEvent = new CreateCarEvent(newDomainObj);
                _ = Task.Run(() => _eventBusPublisher.PublishAsync(createCarEvent));
            }
            else
            {
                Log.Error("CreateCarCommand unsuccessful");
            }

            var newDtoObject = _mapper.Map <CarModel>(newDomainObj);

            return(await Task.FromResult(new CommandResult <CarModel>(newDtoObject, success)));
        }
Beispiel #3
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var version = 1;

            while (!stoppingToken.IsCancellationRequested && version <= 10)
            {
                var @event  = new SampleEvent(subject: Guid.NewGuid().ToString(), version: version++);
                var context = new EventNotification <SampleEvent>(streamId: @event.Subject, @event: @event, correlationId: null, causationId: null, timestamp: @event.Timestamp, userId: null);

                await _eventBusPublisher.PublishAsync(context);

                await Task.Delay(1000);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Publish an IntegrationEvent to external Event Bus
        /// </summary>
        /// <param name="tracker">The tracker</param>
        /// <param name="integrationEvent">The IntegrationEvent needs to be send</param>
        /// <returns></returns>
        protected async Task PublishAsync(IntegrationEvent integrationEvent, ITracker tracker = null)
        {
            if (integrationEvent == null)
            {
                throw new ArgumentNullException(nameof(integrationEvent));
            }

            if (tracker != null)
            {
                integrationEvent.CorrelationId = tracker.CorrelationId;
                integrationEvent.TenantId      = tracker.TenantId;
            }

            await _eventBus.PublishAsync(integrationEvent).ConfigureAwait(false);
        }