public void Execute(Envelope envelope, IEnvelopeContext context) { _task = Task.Factory.StartNew(() => { var continuation = _inner(); continuation.Execute(envelope, context); }); }
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; }
public void Execute(Envelope envelope, IEnvelopeContext context) { context.SendFailureAcknowledgement(envelope, "Moved message {0} to the Error Queue.\n{1}".ToFormat(envelope.CorrelationId, _exception)); var report = new ErrorReport(envelope, _exception); envelope.Callback.MoveToErrors(report); }
public void recovers_delayed_messages_when_started() { using (var queues = new PersistentQueues(new RecordingLogger(), new DelayedMessageCache<MessageId>(), new LightningQueueSettings())) { queues.ClearAll(); queues.Start(new []{ new LightningUri("lq.tcp://localhost:2425/the_queue") }); var envelope = new Envelope(); envelope.Data = new byte[0]; envelope.ExecutionTime = DateTime.UtcNow; var delayedMessage = new MessagePayload { Data = envelope.Data, Headers = envelope.Headers.ToNameValues() }; using (var scope = new TransactionScope()) { queues.ManagerFor(2425, true) .EnqueueDirectlyTo(LightningQueuesTransport.DelayedQueueName, null, delayedMessage); scope.Complete(); } } var cache = new DelayedMessageCache<MessageId>(); using (var queues = new PersistentQueues(new RecordingLogger(), cache, new LightningQueueSettings())) { queues.Start(new []{ new LightningUri("lq.tcp://localhost:2425/the_queue") }); cache.AllMessagesBefore(DateTime.UtcNow.AddSeconds(1)).ShouldNotBeEmpty(); } }
public void SetUp() { theContext = new TestEnvelopeContext(); theEnvelope = ObjectMother.Envelope(); new NoSubscriberHandler().Execute(theEnvelope, theContext); }
public static IEnumerable<EnvelopeToken> DequeueDelayedEnvelopes(DateTime currentTime) { var delayed = _delayedLock.Read(() => { return _delayed.Where(x => new Envelope(x.Headers).ExecutionTime.Value <= currentTime).ToArray(); }); var list = new List<EnvelopeToken>(); foreach (EnvelopeToken token in delayed) { _delayedLock.Write(() => { try { _delayed.Remove(token); var envelope = new Envelope(token.Headers); _queues[envelope.ReceivedAt].Enqueue(token); list.Add(token); } catch (Exception ex) { Debug.WriteLine(ex); } }); } return list; }
// 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 Record(IChainExecutionLog log, Envelope envelope) { log.RecordHeaders(envelope); log.RecordBody(envelope); _storage.Store(log); }
public MonitoringControlHandler(ILogger logger, Envelope envelope, ChannelGraph graph, IPersistentTaskController controller) { _logger = logger; _envelope = envelope; _graph = graph; _controller = controller; }
public void SetUp() { theMessage = new Message1(); theOriginalEnvelope = new Envelope { ReplyUri = "lq://foo".ToUri() }; }
public void SetUp() { _envelope = ObjectMother.Envelope(); _message = new object(); _context = new TestEnvelopeContext(); new RespondWithMessageContinuation(_message).Execute(_envelope, _context); }
public ExceptionHandlerBehavior(IActionBehavior behavior, HandlerChain chain, Envelope envelope, IInvocationContext context, ILogger logger, IFubuRequest request) { _behavior = behavior; Chain = chain; _envelope = envelope; _context = context; _logger = logger; _request = request; }
public static Envelope ToEnvelope(this Message message) { var envelope = new Envelope(new DictionaryHeaders(message.Headers)) { Data = message.Data }; return envelope; }
public ErrorReport(Envelope envelope, Exception ex) { Headers = envelope.Headers.ToNameValues(); ExceptionText = ex.ToString(); ExceptionMessage = ex.Message; ExceptionType = ex.GetType().FullName; Explanation = ExceptionDetected; RawData = envelope.Data; Message = envelope.Message; }
public void matches_negative_with_no_execution_time_header() { var systemTime = SystemTime.Default(); var envelope = new Envelope(); var handler = new DelayedEnvelopeHandler(systemTime); envelope.IsDelayed(systemTime.UtcNow()).ShouldBeFalse(); handler.Matches(envelope).ShouldBeFalse(); }
public virtual void SendSubscriptionChangedToPeer(TransportNode node) { var envelope = new Envelope { Message = new SubscriptionsChanged(), Destination = node.ControlChannel }; _sender.Send(envelope); }
public void SetUp() { theException = new EnvelopeDeserializationException("foo"); theContext = new TestEnvelopeContext(); theEnvelope = ObjectMother.EnvelopeWithSerializationError(); new DeserializationFailureContinuation(theException) .Execute(theEnvelope, theContext); }
public virtual void SendSubscriptionChangedToPeer(TransportNode node) { var envelope = new Envelope { Message = new SubscriptionsChanged(), Destination = node.Addresses.FirstOrDefault() }; _sender.Send(envelope); }
public void Receive(byte[] data, IHeaders headers, IMessageCallback callback) { var envelope = new Envelope(data, headers, callback); lock (_received) { _received.Add(envelope); } envelope.Callback.MarkSuccessful(); }
/* * Changes * 1.) Do serialization within sendToChannel * 2.) do the cloning *outside* of sendToChannel * 3.) Make envelopeserializer smart enough not to replace the contents if it needs to */ private void sendToChannel(Envelope envelope, ChannelNode node) { var replyUri = _router.ReplyUriFor(node); var headers = node.Send(envelope, _serializer, replyUri: replyUri); _logger.InfoMessage(() => new EnvelopeSent(new EnvelopeToken { Headers = headers, Message = envelope.Message }, node)); }
public override IHeaders Send(Envelope envelope, IEnvelopeSerializer serializer, Uri replyUri = null) { if (replyUri != null) { envelope.ReplyUri = replyUri; } LastEnvelope = envelope; return envelope.Headers; }
public void SetUp() { theEnvelope = ObjectMother.Envelope(); theException = new NotImplementedException(); theLogger = MockRepository.GenerateMock<ILogger>(); theContext = new TestEnvelopeContext(); new MoveToErrorQueue(theException).Execute(theEnvelope, theContext); }
public void matches_positive() { var systemTime = SystemTime.Default(); var envelope = new Envelope(); envelope.ExecutionTime = systemTime.UtcNow().AddHours(1); var handler = new DelayedEnvelopeHandler(systemTime); envelope.IsDelayed(systemTime.UtcNow()).ShouldBeTrue(); handler.Matches(envelope).ShouldBeTrue(); }
public void matches_negative_when_the_execution_time_is_in_the_past() { var systemTime = SystemTime.Default(); var envelope = new Envelope(); envelope.ExecutionTime = systemTime.UtcNow().AddHours(-1); var handler = new DelayedEnvelopeHandler(systemTime); envelope.IsDelayed(systemTime.UtcNow()).ShouldBeFalse(); handler.Matches(envelope).ShouldBeFalse(); }
public void SetUp() { theException = new Exception(); theContinuation = new ChainFailureContinuation(theException); theEnvelope = ObjectMother.Envelope(); theContext = new TestEnvelopeContext(); theContinuation.Execute(theEnvelope, theContext); }
public void create_and_send_with_timespan_delayed() { var message = new Message1(); var delayed = new DelayedResponse(message, 5.Minutes()); var original = MockRepository.GenerateMock<Envelope>(); var response = new Envelope(); original.Stub(x => x.ForResponse(message)).Return(response); delayed.CreateEnvelope(original).ShouldBeTheSameAs(response); response.ExecutionTime.ShouldBe(delayed.Time); }
public void create_and_send_to_correct_destination() { var destination = new Uri("memory://blah"); var message = new Message1(); var sendDirectlyTo = new SendDirectlyTo(destination, message); var original = MockRepository.GenerateMock<Envelope>(); var response = new Envelope(); original.Stub(x => x.ForSend(message)).Return(response); sendDirectlyTo.CreateEnvelope(original).ShouldBeTheSameAs(response); response.Destination.ShouldBe(destination); }
public IContinuation Continuation(Envelope envelope, Exception ex) { var count = _sources.Count; switch (count) { case 0: return Requeue; case 1: return _sources.Single().DetermineContinuation(envelope, ex); default: return new CompositeContinuation(_sources.Select(x => x.DetermineContinuation(envelope, ex)).ToArray()); } }
public void Receive(byte[] data, IHeaders headers, IMessageCallback callback) { if (data == null) throw new ArgumentNullException("data"); if (headers == null) throw new ArgumentNullException("headers"); if (callback == null) throw new ArgumentNullException("callback"); var envelope = new Envelope(data, headers, callback) { ReceivedAt = _address }; envelope.ContentType = envelope.ContentType ?? _node.DefaultContentType ?? _graph.DefaultContentType; _pipeline.Receive(envelope); }
public void has_to_set_the_destination_header() { var message = new Message1(); var respondToSender = new RespondToSender(message); var original = MockRepository.GenerateMock<Envelope>(); original.ReplyUri = new Uri("memory://me/reply"); var response = new Envelope(); original.Stub(x => x.ForResponse(message)).Return(response); respondToSender.CreateEnvelope(original).ShouldBeTheSameAs(response); response.Destination.ShouldBe(original.ReplyUri); }