Example #1
0
        public EnvelopeSent(EnvelopeToken envelope, ChannelNode node)
        {
            Envelope = envelope;

            Uri = node.Uri;
            Key = node.Key;
        }
        public void handle_envelope_sent_then_message_failed_for_multiple_messages_to_the_same_node()
        {
            MessageHistory.StartListening();

            var envelope1 = new EnvelopeToken();
            var envelope2 = new EnvelopeToken();
            var node1 = new StubChannelNode();

            var messageWatcher = new MessageWatcher();

            messageWatcher.Handle(new EnvelopeSent(envelope1, node1));
            messageWatcher.Handle(new EnvelopeSent(envelope2, node1));

            MessageHistory.Outstanding().Count().ShouldEqual(2);

            envelope1.Destination = node1.Uri;
            messageWatcher.Handle(new MessageFailed
            {
                Envelope = envelope1
            });

            MessageHistory.Outstanding().Count().ShouldEqual(1);

            envelope2.Destination = node1.Uri;
            messageWatcher.Handle(new MessageFailed
            {
                Envelope = envelope2
            });

            MessageHistory.Outstanding().Any().ShouldBeFalse();
        }
        public void SetUp()
        {
            theToken = ObjectMother.EnvelopeWithMessage().ToToken();
            theToken.ParentId = Guid.NewGuid().ToString();
            theToken.Headers["A"] = "1";
            theToken.Headers["B"] = "2";

            theRecord = new MessageRecord(theToken);
        }
        public void Send(byte[] data, IHeaders headers)
        {
            var envelope = new EnvelopeToken
            {
                Data = data,
                Headers = headers
            };

            _queue.Enqueue(envelope);
        }
        public MessageRecord(EnvelopeToken envelope)
        {
            Id = envelope.CorrelationId;
            ParentId = envelope.ParentId;
            if (envelope.Message != null)
            {
                Type = envelope.Message.GetType().FullName;
            }

            Headers = envelope.Headers.Keys().Select(x => "{0}={1}".ToFormat(x, envelope.Headers[x])).Join(";");
        }
        public void moves_to_delayed_queue()
        {
            InMemoryQueueManager.ClearAll();

            var envelope = new EnvelopeToken();
            var callback = new InMemoryCallback(null, envelope);
            callback.MoveToDelayedUntil(DateTime.Now);

            InMemoryQueueManager.DelayedEnvelopes()
                                .Single().CorrelationId.ShouldEqual(envelope.CorrelationId);
        }
        public void can_round_trip_an_envelope_through_the_queue()
        {
            var envelope = new EnvelopeToken();
            envelope.CorrelationId = Guid.NewGuid().ToString();
            envelope.Headers["Foo"] = "Bar";
            envelope.Data = new byte[] { 1, 2, 3, 4, 5 };

            var queue = new InMemoryQueue(new Uri("memory://foo"));

            var receiver = new RecordingReceiver();
            var task = Task.Factory.StartNew(() => queue.Receive(receiver));

            queue.Enqueue(envelope);

            Wait.Until(() => receiver.Received.Any(), timeoutInMilliseconds: 2000);

            var received = receiver.Received.Single();

            received.CorrelationId.ShouldEqual(envelope.CorrelationId);
            received.ContentType.ShouldEqual(envelope.ContentType);
            received.Data.ShouldEqual(envelope.Data);
            task.SafeDispose();
        }
 public InMemoryCallback(InMemoryQueue parent, EnvelopeToken token)
 {
     _parent = parent;
     _token = token;
 }
        public void Enqueue(EnvelopeToken envelope)
        {
            using (var stream = new MemoryStream())
            {
                _formatter.Serialize(stream, envelope);

                stream.Position = 0;
                var bytes = stream.ReadAllBytes();

                _queue.Add(bytes);
            }
        }
        public void SetUp()
        {
            theEvents = MockRepository.GenerateMock<IEventAggregator>();

            theListener = new ReplyListener<Message1>(theEvents, correlationId, 10.Minutes());

            theMessage = new Message1();

            var envelope = new EnvelopeToken
            {
                Message = theMessage
            };

            envelope.Headers[Envelope.ResponseIdKey] = correlationId;

            theListener.Handle(new EnvelopeReceived
            {
                Envelope = envelope
            });
        }
        public void SetUp()
        {
            theEvents = MockRepository.GenerateMock<IEventAggregator>();

            theListener = new ReplyListener<Message1>(theEvents, correlationId, 10.Minutes());

            var envelope = new EnvelopeToken
            {
                Message = new FailureAcknowledgement
                {
                    CorrelationId = correlationId,
                    Message = "No soup for you!"
                }
            };

            envelope.Headers[Envelope.ResponseIdKey] = correlationId;

            theListener.Handle(new EnvelopeReceived
            {
                Envelope = envelope
            });
        }
 protected bool Equals(EnvelopeToken other)
 {
     return Equals(Data, other.Data) && Equals(Headers, other.Headers);
 }
 public static void AddToDelayedQueue(EnvelopeToken envelope)
 {
     _delayedLock.Write(() => {
         _delayed.Add(envelope);
     });
 }
Example #14
0
 public bool Matches(EnvelopeToken envelope)
 {
     return(envelope.Message is T && envelope.ResponseId == _originalId);
 }
Example #15
0
 protected bool Equals(EnvelopeToken other)
 {
     return(Equals(Data, other.Data) && Equals(Headers, other.Headers));
 }