Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 protected Task <bool> ProcessMessageAsync <T>(T message, QueueMessageContext context,
                                               ReceiveAsyncDelegate <T>?callback = null) where T : class
 {
     callback ??= ReceiveAsync;
     return(_pipeline.ReceiveAsync(message, context, callback));
 }
Exemplo n.º 6
0
 protected abstract Task <QueuePublishResult> DoPublishAsync <T>(T message, QueueMessageContext context)
     where T : class;