コード例 #1
0
        /// <summary>
        /// Called by the bus to indicate that a message has been received that is
        /// related to another message (possibly a reply)
        /// </summary>
        /// <param name="message"></param>
        /// <returns>Returns a task that will complete when all reply stream
        /// observers have been notified that a reply was received</returns>
        public Task NotifyReplyReceived(Message message)
        {
            CheckDisposed();
            var relatedTo = message.Headers.RelatedTo;

            return(Task.Run(() =>
            {
                if (_cache.Get(relatedTo) is ReplyStream replyStream)
                {
                    var messageContent = _messageMarshaller.Unmarshal(message);
                    replyStream.NotifyReplyReceived(messageContent);
                }
                else
                {
                    _diagnosticService.Emit(
                        new DiagnosticEventBuilder(this, DiagnosticEventType.CorrelationFailed)
                    {
                        Message = message,
                        Detail = $"No sent message found with ID {relatedTo}"
                    }.Build());
                }
            }));
        }
コード例 #2
0
ファイル: MessageHandler.cs プロジェクト: sweetlandj/Platibus
        public async Task HandleMessage(IEnumerable <IMessageHandler> messageHandlers, Message message,
                                        IMessageContext messageContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (message.Headers.Expires < DateTime.UtcNow)
            {
                await _diagnosticService.EmitAsync(
                    new DiagnosticEventBuilder(this, DiagnosticEventType.MessageExpired)
                {
                    Detail  = "Discarding message that expired " + message.Headers.Expires,
                    Message = message
                }.Build(), cancellationToken);

                messageContext.Acknowledge();
                return;
            }

            var messageContent = _messageMarshaller.Unmarshal(message);

            var handlingTasks = messageHandlers.Select(handler =>
                                                       handler.HandleMessage(messageContent, messageContext, cancellationToken));

            await Task.WhenAll(handlingTasks);
        }