async Task ISendTransport.Send <T>(T message, IPipe <SendContext <T> > pipe, CancellationToken cancelSend)
        {
            var context = new InMemorySendContext <T>(message, cancelSend);

            try
            {
                await pipe.Send(context).ConfigureAwait(false);

                var messageId = context.MessageId ?? NewId.NextGuid();

                await _sendObservable.PreSend(context).ConfigureAwait(false);

                var transportMessage = new InMemoryTransportMessage(messageId, context.Body, context.ContentType.MediaType, TypeMetadataCache <T> .ShortName);

                await _exchange.Send(transportMessage).ConfigureAwait(false);

                context.LogSent();

                await _sendObservable.PostSend(context).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                context.LogFaulted(ex);

                await _sendObservable.SendFault(context, ex).ConfigureAwait(false);

                throw;
            }
        }
예제 #2
0
        protected async Task Move(ReceiveContext context, Action <InMemoryTransportMessage, SendHeaders> preSend)
        {
            var messageId = GetMessageId(context);

            byte[] body = context.GetBody();

            var messageType = "Unknown";

            if (context.TryGetPayload(out InMemoryTransportMessage receivedMessage))
            {
                messageType = receivedMessage.MessageType;
            }

            var transportMessage = new InMemoryTransportMessage(messageId, body, context.ContentType.MediaType, messageType);

            SendHeaders headers = new DictionarySendHeaders(transportMessage.Headers);

            headers.SetHostHeaders();

            preSend(transportMessage, headers);

            transportMessage.Headers[MessageHeaders.Reason] = "dead-letter";

            await _exchange.Send(transportMessage).ConfigureAwait(false);
        }
예제 #3
0
        protected async Task Move(ReceiveContext context, Action <InMemoryTransportMessage, IDictionary <string, object> > preSend)
        {
            var messageId = GetMessageId(context);

            byte[] body = context.GetBody();

            var messageType = "Unknown";

            if (context.TryGetPayload(out InMemoryTransportMessage receivedMessage))
            {
                messageType = receivedMessage.MessageType;
            }

            var transportMessage = new InMemoryTransportMessage(messageId, body, context.ContentType?.MediaType, messageType);

            transportMessage.Headers.SetHostHeaders();

            preSend(transportMessage, transportMessage.Headers);

            await _exchange.Send(transportMessage, CancellationToken.None).ConfigureAwait(false);
        }