private QueueMessageContext GetMessageContext <T>(QueueMessageContext?parentMessageContext = null) { var messageContext = new QueueMessageContext { MessageType = typeof(T).FullName, RequestId = parentMessageContext?.RequestId, ParentMessageId = parentMessageContext?.Id, RootMessageId = parentMessageContext?.RootMessageId, RootMessageDate = parentMessageContext?.RootMessageDate, ReplyTo = parentMessageContext?.ReplyTo }; if (parentMessageContext?.RootMessageId != null) { messageContext.RootMessageId = parentMessageContext.RootMessageId; messageContext.RootMessageDate = parentMessageContext.RootMessageDate; } else { messageContext.RootMessageId = messageContext.Id; messageContext.RootMessageDate = messageContext.Date; } return(messageContext); }
private async Task <bool> ReceiveAsync <T>(T message, QueueMessageContext context) where T : class { var subscriptions = _subscriptions.Values.Where(s => s is QueueSubscription <T>).ToList(); if (!subscriptions.Any()) { return(false); } foreach (var subscription in subscriptions) { if (subscription is QueueSubscription <T> payloadSubscription) { try { await payloadSubscription.ProcessAsync(message, context); } catch (Exception ex) { _logger.LogError(ex, "Error while processing message {MessageType}: {ErrorText}", message.GetType(), ex.ToString()); } } } return(true); }
public virtual Task <bool> ReceiveAsync <T>(T message, QueueMessageContext messageContext, ReceiveAsyncDelegate <T>?callback = null) where T : class { if (Next != null) { return(Next.ReceiveAsync(message, messageContext, callback)); } return(callback != null?callback(message, messageContext) : Task.FromResult(false)); }
public virtual Task <QueuePublishResult> PublishAsync <T>(T message, QueueMessageContext messageContext, PublishAsyncDelegate <T>?callback = null) where T : class { if (Next != null) { return(Next.PublishAsync(message, messageContext, callback)); } if (callback != null) { return(callback(message, messageContext)); } var result = new QueuePublishResult(); result.SetError("Message reached end of pipeline"); return(Task.FromResult(result)); }
protected Task <bool> ProcessMessageAsync <T>(T message, QueueMessageContext context, ReceiveAsyncDelegate <T>?callback = null) where T : class { callback ??= ReceiveAsync; return(_pipeline.ReceiveAsync(message, context, callback)); }
protected abstract Task <QueuePublishResult> DoPublishAsync <T>(T message, QueueMessageContext context) where T : class;