public async Task ReceiveAsync(Command command, CancellationToken cancellationToken) { if (command.Status != CommandStatus.Pending) { return; } try { using (EnvelopeReceiverContext <Command> .Create(command)) { await CallReceiversAsync(command, cancellationToken); } } catch (Exception ex) { LogException(command, ex); await _sender.SendCommandAsync(new Command { Id = command.Id, To = command.From, Method = command.Method, Status = CommandStatus.Failure, Reason = ex.ToReason(), }, cancellationToken); } }
public async Task ReceiveAsync(Notification notification, CancellationToken cancellationToken) { try { using (EnvelopeReceiverContext <Notification> .Create(notification)) { await CallReceiversAsync(notification, cancellationToken); } } catch (Exception ex) { LogException(notification, ex); } }
public async Task ReceiveAsync(Message message, CancellationToken cancellationToken) { var shouldNotify = _autoNotify && !string.IsNullOrWhiteSpace(message?.Id); try { if (shouldNotify) { await _sender.SendNotificationAsync(message.ToReceivedNotification(), cancellationToken); } using (EnvelopeReceiverContext <Message> .Create(message)) { await CallReceiversAsync(message, cancellationToken); } if (shouldNotify) { await _sender.SendNotificationAsync(message.ToConsumedNotification(), cancellationToken); } } catch (Exception ex) { using (LogContext.PushProperty(nameof(Message.Type), message?.Type)) { LogException(message, ex); } // Always notify failures if (!string.IsNullOrWhiteSpace(message?.Id)) { Reason reason; if (ex is LimeException limeException) { reason = limeException.Reason; } else { reason = new Reason { Code = ReasonCodes.APPLICATION_ERROR, Description = ex.Message }; } await _sender.SendNotificationAsync(message.ToFailedNotification(reason), CancellationToken.None); } } }
private async Task <bool> HandleMessageAsync(Message message, CancellationToken cancellationToken) { try { if (_autoNotify) { await _sender.SendNotificationAsync(message.ToReceivedNotification(), cancellationToken); } using (EnvelopeReceiverContext <Message> .Create(message)) { await CallReceiversAsync(message, cancellationToken); } if (_autoNotify) { await _sender.SendNotificationAsync(message.ToConsumedNotification(), cancellationToken); } } catch (Exception ex) { using (LogContext.PushProperty(nameof(Message.Type), message.Type)) { LogException(message, ex); } Reason reason; if (ex is LimeException limeException) { reason = limeException.Reason; } else { reason = new Reason { Code = ReasonCodes.APPLICATION_ERROR, Description = ex.Message }; } if (_autoNotify) { await _sender.SendNotificationAsync(message.ToFailedNotification(reason), CancellationToken.None); } } return(true); }
private async Task <bool> HandleNotificationAsync(Notification notification, CancellationToken cancellationToken) { try { using (EnvelopeReceiverContext <Notification> .Create(notification)) { await CallReceiversAsync(notification, cancellationToken); } } catch (Exception ex) { LogException(notification, ex); } return(true); }