コード例 #1
0
        public DistributeMessageEventArgs(PipelineEvent pipelineEvent, IQueue destinationQueue,
		                                  TransportMessage transportMessage)
            : base(pipelineEvent)
        {
            DestinationQueue = destinationQueue;
            TransportMessage = transportMessage;
        }
コード例 #2
0
        public MessageSenderContext(TransportMessage transportMessage, TransportMessage transportMessageReceived)
        {
            Guard.AgainstNull(transportMessage, "transportMessage");

            TransportMessage = transportMessage;
            TransportMessageReceived = transportMessageReceived;
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public MessageSender(IServiceBus bus, TransportMessage transportMessageReceived)
        {
            Guard.AgainstNull(bus, "bus");

            _bus = bus;
            _transportMessageReceived = transportMessageReceived;

            _log = Log.For(this);
        }
コード例 #5
0
        public bool Execute(TransportMessage transportMessage, TransportMessage transportMessageReceived)
        {
            Guard.AgainstNull(transportMessage, "transportMessage");

            State.SetTransportMessage(transportMessage);
            State.SetTransportMessageReceived(transportMessageReceived);

            return base.Execute();
        }
コード例 #6
0
 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));
     }
 }
コード例 #7
0
 public void Add(TransportMessage transportMessage)
 {
     using (databaseConnectionFactory.Create(IdempotenceDataSource))
     {
         databaseGateway.ExecuteUsing(
             IdempotenceDataSource,
             RawQuery.CreateFrom(
                 scriptProvider.GetScript(Script.IdempotenceTrackerAdd))
                     .AddParameterValue(IdempotenceTrackerColumns.MessageId, transportMessage.MessageId));
     }
 }
コード例 #8
0
        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;
        }
コード例 #9
0
 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;
     }
 }
コード例 #10
0
ファイル: MessageView.cs プロジェクト: nnyamhon/shuttle-esb
        public void Show(TransportMessage transportMessage, object message)
        {
            Clear();

            if (transportMessage == null)
            {
                return;
            }

            Populate(message, transportMessage, typeof (TransportMessage), 0);

            ValueColumn.Width = -1;
        }
コード例 #11
0
        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());
        }
コード例 #12
0
        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;
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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;
        }
コード例 #16
0
        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);
        }
コード例 #17
0
 public static void SetTransportMessage(this PipelineEvent pipelineEvent, TransportMessage value)
 {
     pipelineEvent.Pipeline.State.Replace(StateKeys.TransportMessage, value);
 }
コード例 #18
0
 public MessageSerializationEventArgs(PipelineEvent pipelineEvent, TransportMessage transportMessage, object message)
     : base(pipelineEvent)
 {
     TransportMessage = transportMessage;
     Message = message;
 }
コード例 #19
0
 public static void SetTransportMessage(this PipelineEvent pipelineEvent, TransportMessage value)
 {
     pipelineEvent.Pipeline.State.Replace(StateKeys.TransportMessage, value);
 }
コード例 #20
0
 public AfterHandleMessageEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, TransportMessage transportMessage)
     : base(pipelineEvent)
 {
     WorkQueue = workQueue;
     TransportMessage = transportMessage;
 }
コード例 #21
0
 public MessageSenderContext(TransportMessage transportMessage)
     : this(transportMessage, null)
 {
 }
コード例 #22
0
 public static void SetTransportMessageReceived(this State <Pipeline> state, TransportMessage value)
 {
     state.Replace(StateKeys.TransportMessageReceived, value);
 }
コード例 #23
0
 public QueueMessageEventArgs(PipelineEvent pipelineEvent, IQueue queue, TransportMessage message)
     : base(pipelineEvent)
 {
     Queue = queue;
     TransportMessage = message;
 }
コード例 #24
0
        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;
        }
コード例 #25
0
        public void TransportMessageReceived(TransportMessage transportMessageReceived)
        {
            Guard.AgainstNull(transportMessageReceived, "transportMessageReceived");

            _transportMessageReceived = transportMessageReceived;

            Headers.Merge(transportMessageReceived.Headers);
            _correlationId = transportMessageReceived.CorrelationId;
        }
コード例 #26
0
ファイル: ServiceBus.cs プロジェクト: jessezhao/shuttle-esb
        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;
        }
コード例 #27
0
 public static void SetTransportMessage(this State<ObservablePipeline> state, TransportMessage value)
 {
     state.Replace(StateKeys.TransportMessage, value);
 }
コード例 #28
0
 public void ShowMessage(TransportMessage transportMessage, object message)
 {
     this.Invoke(() => MessageView.Show(transportMessage, message));
 }
コード例 #29
0
ファイル: ServiceBus.cs プロジェクト: jessezhao/shuttle-esb
        public void HandlingTransportMessage(TransportMessage transportMessage)
        {
            _transportMessageBeingHandled = transportMessage;

            ResetOutgoingHeaders();

            if (transportMessage == null)
            {
                outgoingCorrelationId = string.Empty;

                return;
            }

            outgoingCorrelationId = _transportMessageBeingHandled.CorrelationId;
            outgoingHeaders.Merge(transportMessage.Headers);
        }
コード例 #30
0
ファイル: ServiceBus.cs プロジェクト: jessezhao/shuttle-esb
        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);
            }
        }
コード例 #31
0
 public QueueMessageEventArgs(PipelineEvent pipelineEvent, IQueue queue, TransportMessage message)
     : base(pipelineEvent)
 {
     Queue            = queue;
     TransportMessage = message;
 }
コード例 #32
0
 public void Dispatch(TransportMessage transportMessage)
 {
     _messageSender.Dispatch(transportMessage);
 }
コード例 #33
0
        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();
                }
            }
        }
コード例 #34
0
ファイル: ServiceBus.cs プロジェクト: jessezhao/shuttle-esb
 public void TransportMessageHandled()
 {
     _transportMessageBeingHandled = null;
 }