protected async Task RaiseRejectedEventAction(RejectedEvent <T> rejectedEvent)
        {
            Func <RejectedEvent <T>, Task> rejectedEventAction;

            if (_rejectedEventActions.TryGetValue(rejectedEvent.ChangeType, out rejectedEventAction))
            {
                await rejectedEventAction(rejectedEvent);
            }
        }
        // RabbitMQ retry that will publish a message to the retry queue.
        // Keep in mind that it might get processed by the other services using the same routing key and wildcards.
        private async Task <Acknowledgement> TryHandleWithRequeuingAsync <TMessage>(TMessage message,
                                                                                    CorrelationContext correlationContext,
                                                                                    Func <Task> handle, Func <TMessage, CustomException, IRejectedEvent> onError = null)
        {
            var messageName  = message.GetType().Name;
            var retryMessage = correlationContext.Retries == 0
                ? string.Empty
                : $"Retry: {correlationContext.Retries}'.";

            _logger.LogInformation($"Handling a message: '{messageName}' " +
                                   $"with correlation id: '{correlationContext.Id}'. {retryMessage}");

            try
            {
                await handle();

                _logger.LogInformation($"Handled a message: '{messageName}' " +
                                       $"with correlation id: '{correlationContext.Id}'. {retryMessage}");

                return(new Ack());
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, exception.Message);
                if (exception is CustomException CustomException && onError != null)
                {
                    var rejectedEvent = onError(message, CustomException);
                    await _busClient.PublishAsync(rejectedEvent, ctx => ctx.UseMessageContext(correlationContext));

                    _logger.LogInformation($"Published a rejected event: '{rejectedEvent.GetType().Name}' " +
                                           $"for the message: '{messageName}' with correlation id: '{correlationContext.Id}'.");

                    return(new Ack());
                }

                if (correlationContext.Retries >= _retries)
                {
                    await _busClient.PublishAsync(RejectedEvent.For(messageName),
                                                  ctx => ctx.UseMessageContext(correlationContext));

                    throw new Exception($"Unable to handle a message: '{messageName}' " +
                                        $"with correlation id: '{correlationContext.Id}' " +
                                        $"after {correlationContext.Retries} retries.", exception);
                }

                _logger.LogInformation($"Unable to handle a message: '{messageName}' " +
                                       $"with correlation id: '{correlationContext.Id}', " +
                                       $"retry {correlationContext.Retries}/{_retries}...");

                return(Retry.In(TimeSpan.FromSeconds(_retryInterval)));
            }
        }
        protected virtual async Task RejectedModifyChangeRequestAction(RejectedEvent <T> rejectedEvent)
        {
            var existingEntity = RepositoryService.FindAsync(Convert.ToInt32(rejectedEvent.EntityId)).Result;

            // note: change request id is required for documentIndexer. this will eventually be cleared after indexer processing.
            existingEntity.ChangeRequestId = rejectedEvent.ChangeRequestId;

            RepositoryService.Update(existingEntity);
            if (await Repositories.SaveChangesAsync() > 0)
            {
                // clear change request id in azure
                await DocumentIndexer.RejectChangeRequestIndexerAsync(rejectedEvent.ChangeRequestId);

                // clear change request id in transaction table
                await this.ClearChangeRequestId <T>(rejectedEvent.ChangeRequestId);
            }
        }
 public async Task HandleAsync(RejectedEvent <Make> changeRequestRejectedEvent)
 {
     await RaiseRejectedEventAction(changeRequestRejectedEvent);
 }
 public async Task HandleAsync(RejectedEvent <BodyNumDoors> changeRequestRejectedEvent)
 {
     await RaiseRejectedEventAction(changeRequestRejectedEvent);
 }
Example #6
0
 public async Task HandleAsync(RejectedEvent <VehicleTypeGroup> changeRequestRejectedEvent)
 {
     await RaiseRejectedEventAction(changeRequestRejectedEvent);
 }
        protected override async Task RejectedReplaceChangeRequestAction(RejectedEvent <VehicleToDriveType> rejectedEvent)
        {
            await base.RejectedReplaceChangeRequestAction(rejectedEvent);

            await ClearChangeRequestId <DriveType>(rejectedEvent.ChangeRequestId);
        }
 public async Task SetRejectedEvent(string id, RejectedEvent @event)
 {
     var filter = FilterBuilder.Where(shipment => shipment.Id == ObjectId.Parse(id));
     var update = UpdateBuilder.Set(shipment => shipment.RejectedEvent, @event);
     await Collections.Shipments.UpdateOneAsync(filter, update);
 }
Example #9
0
 public async Task HandleAsync(RejectedEvent <VehicleToMfrBodyCode> changeRequestRejectedEvent)
 {
     await RaiseRejectedEventAction(changeRequestRejectedEvent);
 }
 protected virtual async Task RejectedDeleteChangeRequestAction(RejectedEvent <T> rejectedEvent)
 {
     // note: this has same effect as modify in transaction table
     await this.RejectedModifyChangeRequestAction(rejectedEvent);
 }
 protected virtual async Task RejectedAddChangeRequestAction(RejectedEvent <T> rejectedEvent)
 {
     //note: during reject of add request, nothing is to be done at transaction tables
     // do nothing
     return;
 }
Example #12
0
 public void OnRejected(RejectedEvent rejected)
 {
     this.rejected = rejected;
     CPP.Add("QObject::connect($q, &QDialog::rejected, [=] () {this->SlotRejected();});");
 }
 public async Task Publish(RejectedEvent evt)
 {
     await _hub.Clients.Groups(evt.Code).SendAsync("status_fail", new { id = evt.Code, cause = evt.Reason });
 }
Example #14
0
        public async Task RejectedEvent(string id, RejectedEvent @event)
        {
            await ShipmentEntity.ValidateId(id);

            await ShipmentDAO.Methods.UpdateSet.SetRejectedEvent(id, @event);
        }
Example #15
0
 public async Task HandleAsync(RejectedEvent <VehicleToBedConfig> changeRequestRejectedEvent)
 {
     await RaiseRejectedEventAction(changeRequestRejectedEvent);
 }
Example #16
0
 public async Task HandleAsync(RejectedEvent <VehicleToWheelBase> changeRequestRejectedEvent)
 {
     await RaiseRejectedEventAction(changeRequestRejectedEvent);
 }
Example #17
0
        protected override async Task RejectedReplaceChangeRequestAction(RejectedEvent <VehicleToBedConfig> rejectedEvent)
        {
            await base.RejectedReplaceChangeRequestAction(rejectedEvent);

            await ClearChangeRequestId <BedConfig>(rejectedEvent.ChangeRequestId);
        }
Example #18
0
 public async Task HandleAsync(RejectedEvent <BodyStyleConfig> changeRequestRejectedEvent)
 {
     await RaiseRejectedEventAction(changeRequestRejectedEvent);
 }