Example #1
0
        public string Send(Envelope envelope)
        {
            prepareEnvelopeForSending(envelope);

            var channels = _router.FindDestinationChannels(envelope).ToArray();

            if (!channels.Any())
            {
                throw new Exception("No channels match this message ({0})".ToFormat(envelope));
            }

            channels.Each(x => {
                try
                {
                    sendToChannel(envelope, x);
                }
                catch (Exception e)
                {
                    _logger.Error(envelope.CorrelationId, "Failed trying to send message {0} to channel {1}".ToFormat(envelope, x.Uri), e);
                    throw;
                }
            });

            return(envelope.CorrelationId);
        }
Example #2
0
        // virtual for testing
        public string Send(Envelope envelope)
        {
            envelope.Headers[Envelope.MessageTypeKey] = envelope.Message.GetType().FullName;

            _modifiers.Each(x => x.Modify(envelope));

            var channels = _router.FindDestinationChannels(envelope).ToArray();

            if (!channels.Any())
            {
                throw new Exception("No channels match this message ({0})".ToFormat(envelope));
            }

            channels.Each(x => {
                try
                {
                    sendToChannel(envelope, x);
                }
                catch (Exception e)
                {
                    _logger.Error(envelope.CorrelationId, "Failed trying to send message {0} to channel {1}".ToFormat(envelope, x.Uri), e);
                    throw;
                }
            });

            return(envelope.CorrelationId);
        }
        public void if_destination_is_set_on_the_envelope_that_is_the_only_channel_returned()
        {
            var envelope = new Envelope
            {
                Message     = new Message1(),
                Destination = settings.Service4
            };

            theRouter.FindDestinationChannels(envelope).Single().Uri.ShouldBe(settings.Service4);
        }