public DistributeMessageEventArgs(PipelineEvent pipelineEvent, IQueue destinationQueue, TransportMessage transportMessage) : base(pipelineEvent) { DestinationQueue = destinationQueue; TransportMessage = transportMessage; }
public MessageSenderContext(TransportMessage transportMessage, TransportMessage transportMessageReceived) { Guard.AgainstNull(transportMessage, "transportMessage"); TransportMessage = transportMessage; TransportMessageReceived = transportMessageReceived; }
public void Should_be_able_to_serialize_and_deserialize_at_least_500_instances_with_a_simple_type_in_a_second() { var original = new TransportMessage { Message = SUT().Serialize(new SimpleCommand { Name = "SimpleMessage" }).ToBytes() }; var serializer = SUT(); var sw = new Stopwatch(); sw.Start(); const int REQUIREDCOUNT = 500; for (var i = 0; i < REQUIREDCOUNT; i++) { serializer.Deserialize(typeof(TransportMessage), serializer.Serialize(original)); } sw.Stop(); Console.WriteLine("Serialized/Deserialized {0} instances in {1} ms", REQUIREDCOUNT, sw.ElapsedMilliseconds); Assert.IsTrue(sw.ElapsedMilliseconds < 1000, "Should be able to serialize and deserialize at least {0} instances with a simple type in a second", REQUIREDCOUNT); }
public MessageSender(IServiceBus bus, TransportMessage transportMessageReceived) { Guard.AgainstNull(bus, "bus"); _bus = bus; _transportMessageReceived = transportMessageReceived; _log = Log.For(this); }
public bool Execute(TransportMessage transportMessage, TransportMessage transportMessageReceived) { Guard.AgainstNull(transportMessage, "transportMessage"); State.SetTransportMessage(transportMessage); State.SetTransportMessageReceived(transportMessageReceived); return base.Execute(); }
public void DeferredMessageSent(TransportMessage processingTransportMessage, TransportMessage deferredTransportMessage) { using (_databaseConnectionFactory.Create(IdempotenceDataSource)) { _databaseGateway.ExecuteUsing( IdempotenceDataSource, RawQuery.Create(_scriptProvider.GetScript(Script.IdempotenceDeferredMessageSent)) .AddParameterValue(IdempotenceColumns.MessageId, processingTransportMessage.MessageId)); } }
public void Add(TransportMessage transportMessage) { using (databaseConnectionFactory.Create(IdempotenceDataSource)) { databaseGateway.ExecuteUsing( IdempotenceDataSource, RawQuery.CreateFrom( scriptProvider.GetScript(Script.IdempotenceTrackerAdd)) .AddParameterValue(IdempotenceTrackerColumns.MessageId, transportMessage.MessageId)); } }
public HandlerExceptionEventArgs(PipelineEvent pipelineEvent, TransportMessage transportMessage, object message, IQueue workQueue, IQueue errorQueue, Exception exception) : base(pipelineEvent) { TransportMessage = transportMessage; Message = message; WorkQueue = workQueue; ErrorQueue = errorQueue; Exception = exception; }
public bool Contains(TransportMessage transportMessage) { using (databaseConnectionFactory.Create(IdempotenceDataSource)) { return databaseGateway.GetScalarUsing<int>( IdempotenceDataSource, RawQuery.CreateFrom( scriptProvider.GetScript( Script.IdempotenceTrackerContains)) .AddParameterValue(IdempotenceTrackerColumns.MessageId, transportMessage.MessageId)) == 1; } }
public void Show(TransportMessage transportMessage, object message) { Clear(); if (transportMessage == null) { return; } Populate(message, transportMessage, typeof (TransportMessage), 0); ValueColumn.Width = -1; }
public void Should_be_able_to_determine_if_message_should_be_ignored() { var messsage = new TransportMessage() { IgnoreTillDate = DateTime.Now.AddMinutes(1) }; Assert.IsTrue(messsage.IsIgnoring()); messsage.IgnoreTillDate = DateTime.Now.AddMilliseconds(-1); Assert.IsFalse(messsage.IsIgnoring()); }
public MessageNotHandledEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue, TransportMessage transportMessage, object message) : base(pipelineEvent) { Guard.AgainstNull(pipelineEvent, "pipelineEvent"); Guard.AgainstNull(workQueue, "workQueue"); Guard.AgainstNull(errorQueue, "errorQueue"); Guard.AgainstNull(transportMessage, "transportMessage"); Guard.AgainstNull(message, "message"); WorkQueue = workQueue; ErrorQueue = errorQueue; TransportMessage = transportMessage; Message = message; }
public void Dispatch(TransportMessage transportMessage) { Guard.AgainstNull(transportMessage, "transportMessage"); var messagePipeline = _bus.Configuration.PipelineFactory.GetPipeline<DispatchTransportMessagePipeline>(_bus); try { messagePipeline.Execute(transportMessage, _transportMessageReceived); } finally { _bus.Configuration.PipelineFactory.ReleasePipeline(messagePipeline); } }
public void Should_be_able_to_serialize_and_deserialize_a_transport_message() { var original = new TransportMessage(); var sut = SUT(); var stream = sut.Serialize(original); var xml = new StreamReader(stream).ReadToEnd(); Assert.IsTrue(xml.Contains(original.MessageId.ToString())); stream.Position = 0; Assert.AreEqual(original.MessageId, ((TransportMessage)sut.Deserialize(typeof(TransportMessage), stream)).MessageId); }
public IEnumerable<Stream> GetDeferredMessages(TransportMessage transportMessage) { var result = new List<Stream>(); using (_databaseConnectionFactory.Create(IdempotenceDataSource)) { var rows = _databaseGateway.GetRowsUsing( IdempotenceDataSource, RawQuery.Create(_scriptProvider.GetScript(Script.IdempotenceGetDeferredMessages)) .AddParameterValue(IdempotenceColumns.MessageId, transportMessage.MessageId)); foreach (var row in rows) { result.Add(new MemoryStream((byte[]) row["MessageBody"])); } } return result; }
public void Should_be_able_to_register_failures_and_have_IgnoreTillDate_set() { var message = new TransportMessage(); var before = DateTime.Now; message.RegisterFailure("failure"); Assert.IsTrue(before <= message.IgnoreTillDate); message = new TransportMessage(); var durationToIgnoreOnFailure = new[] { TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(30), TimeSpan.FromHours(2) }; Assert.IsFalse(DateTime.Now.AddMinutes(3) <= message.IgnoreTillDate); message.RegisterFailure("failure", durationToIgnoreOnFailure[0]); Assert.IsTrue(DateTime.Now.AddMinutes(3) <= message.IgnoreTillDate); Assert.IsFalse(DateTime.Now.AddMinutes(30) <= message.IgnoreTillDate); message.RegisterFailure("failure", durationToIgnoreOnFailure[1]); Assert.IsTrue(DateTime.Now.AddMinutes(30) <= message.IgnoreTillDate); Assert.IsFalse(DateTime.Now.AddHours(2) <= message.IgnoreTillDate); message.RegisterFailure("failure", durationToIgnoreOnFailure[2]); Assert.IsTrue(DateTime.Now.AddHours(2) <= message.IgnoreTillDate); }
public static void SetTransportMessage(this PipelineEvent pipelineEvent, TransportMessage value) { pipelineEvent.Pipeline.State.Replace(StateKeys.TransportMessage, value); }
public MessageSerializationEventArgs(PipelineEvent pipelineEvent, TransportMessage transportMessage, object message) : base(pipelineEvent) { TransportMessage = transportMessage; Message = message; }
public AfterHandleMessageEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, TransportMessage transportMessage) : base(pipelineEvent) { WorkQueue = workQueue; TransportMessage = transportMessage; }
public MessageSenderContext(TransportMessage transportMessage) : this(transportMessage, null) { }
public static void SetTransportMessageReceived(this State <Pipeline> state, TransportMessage value) { state.Replace(StateKeys.TransportMessageReceived, value); }
public QueueMessageEventArgs(PipelineEvent pipelineEvent, IQueue queue, TransportMessage message) : base(pipelineEvent) { Queue = queue; TransportMessage = message; }
public TransportMessage TransportMessage(IServiceBusConfiguration configuration) { if (_local && !configuration.HasInbox) { throw new InvalidOperationException(ESBResources.SendToSelfException); } var identity = WindowsIdentity.GetCurrent(); var result = new TransportMessage { RecipientInboxWorkQueueUri = _local ? configuration.Inbox.WorkQueue.Uri.ToString() : _recipientInboxWorkQueueUri, SenderInboxWorkQueueUri = configuration.HasInbox ? configuration.Inbox.WorkQueue.Uri.ToString() : string.Empty, PrincipalIdentityName = identity != null ? identity.Name : WindowsIdentity.GetAnonymous().Name, IgnoreTillDate = _ignoreTillDate, MessageType = Message.GetType().FullName, AssemblyQualifiedName = Message.GetType().AssemblyQualifiedName, EncryptionAlgorithm = configuration.EncryptionAlgorithm, CompressionAlgorithm = configuration.CompressionAlgorithm, MessageReceivedId = HasTransportMessageReceived ? _transportMessageReceived.MessageId : Guid.Empty, CorrelationId = _correlationId, SendDate = DateTime.Now }; result.Headers.Merge(Headers); return result; }
public void TransportMessageReceived(TransportMessage transportMessageReceived) { Guard.AgainstNull(transportMessageReceived, "transportMessageReceived"); _transportMessageReceived = transportMessageReceived; Headers.Merge(transportMessageReceived.Headers); _correlationId = transportMessageReceived.CorrelationId; }
public TransportMessage CreateTransportMessage(object message) { Guard.AgainstNull(message, "message"); var result = new TransportMessage(); var identity = WindowsIdentity.GetCurrent(); result.SenderInboxWorkQueueUri = Configuration.HasInbox ? Configuration.Inbox.WorkQueue.Uri.ToString() : string.Empty; result.PrincipalIdentityName = identity != null ? identity.Name : WindowsIdentity.GetAnonymous().Name; if (result.SendDate == DateTime.MinValue) { result.SendDate = DateTime.Now; } result.Message = Configuration.Serializer.Serialize(message).ToBytes(); result.MessageType = message.GetType().FullName; result.AssemblyQualifiedName = message.GetType().AssemblyQualifiedName; result.EncryptionAlgorithm = Configuration.EncryptionAlgorithm; result.CompressionAlgorithm = Configuration.CompressionAlgorithm; if (_transportMessageBeingHandled != null) { result.MessageReceivedId = _transportMessageBeingHandled.MessageId; } return result; }
public static void SetTransportMessage(this State<ObservablePipeline> state, TransportMessage value) { state.Replace(StateKeys.TransportMessage, value); }
public void ShowMessage(TransportMessage transportMessage, object message) { this.Invoke(() => MessageView.Show(transportMessage, message)); }
public void HandlingTransportMessage(TransportMessage transportMessage) { _transportMessageBeingHandled = transportMessage; ResetOutgoingHeaders(); if (transportMessage == null) { outgoingCorrelationId = string.Empty; return; } outgoingCorrelationId = _transportMessageBeingHandled.CorrelationId; outgoingHeaders.Merge(transportMessage.Headers); }
public void Send(TransportMessage transportMessage) { Guard.AgainstNull(transportMessage, "transportMessage"); var messagePipeline = Configuration.PipelineFactory.GetPipeline<SendTransportMessagePipeline>(this); messagePipeline.State.SetTransportMessage(transportMessage); if (log.IsTraceEnabled) { log.Trace(string.Format(ESBResources.TraceSend, transportMessage.MessageType, transportMessage.RecipientInboxWorkQueueUri)); } try { messagePipeline.Execute(); } finally { Configuration.PipelineFactory.ReleasePipeline(messagePipeline); } }
public void Dispatch(TransportMessage transportMessage) { _messageSender.Dispatch(transportMessage); }
private void InvokeHandler(IServiceBus bus, IMessageHandler handler, TransportMessage transportMessage, object message, PipelineEvent pipelineEvent, Type messageType) { var contextType = typeof(HandlerContext <>).MakeGenericType(new[] { messageType }); var method = handler.GetType().GetMethod("ProcessMessage", new[] { contextType }); Guard.Against <ProcessMessageMethodMissingException>(method == null, string.Format( ESBResources.ProcessMessageMethodMissingException, handler.GetType().FullName, transportMessage.MessageType)); if (log.IsTraceEnabled) { log.Trace(string.Format(ESBResources.TraceCorrelationIdReceived, transportMessage.CorrelationId)); foreach (var header in transportMessage.Headers) { log.Trace(string.Format(ESBResources.TraceTransportHeaderReceived, header.Key, header.Value)); } log.Trace(string.Format(ESBResources.MessageHandlerInvoke, transportMessage.MessageType, transportMessage.MessageId, handler.GetType().FullName)); } IServiceBusTransactionScope scope = null; try { if (!pipelineEvent.GetHasJournalQueue()) { scope = bus.Configuration.TransactionScopeFactory.Create(); } if (bus.Configuration.HasIdempotenceTracker) { bus.Configuration.IdempotenceTracker.Add(transportMessage); if (log.IsTraceEnabled) { log.Trace(string.Format(ESBResources.TraceIdempotenceTrackerAdd, transportMessage.MessageType, transportMessage.MessageId)); } } method.Invoke(handler, new[] { Activator.CreateInstance(contextType, new[] { bus, transportMessage, message, pipelineEvent.GetActiveState() }) }); if (scope != null) { scope.Complete(); } } catch (Exception ex) { var exception = ex.TrimLeading <TargetInvocationException>(); bus.Events.OnHandlerException( this, new HandlerExceptionEventArgs( pipelineEvent, handler, transportMessage, message, pipelineEvent.GetWorkQueue(), pipelineEvent.GetErrorQueue(), exception)); throw exception; } finally { if (scope != null) { scope.Dispose(); } } }
public void TransportMessageHandled() { _transportMessageBeingHandled = null; }