示例#1
0
 public void OnSucceeded(IBus bus, IMessageInformation info)
 {
     if (info.MessageType != typeof(MessageInformation))
     {
         bus.Send(Convert(info));
     }
 }
示例#2
0
        public FailedMessageInformation(
            IMessageInformation info,
            FailedMessageQueueAction action,
            FailedMessageReason reason,
            Exception exception
            )
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (exception != null)
            {
                while (exception is TargetInvocationException && exception.InnerException != null)
                {
                    exception = exception.InnerException;
                }
            }

            _info        = info;
            FailedAction = action;
            FailedReason = reason;
            Exception    = exception;
        }
示例#3
0
 public void OnSucceeded(IBus bus, IMessageInformation info)
 {
     if (info.MessageType != typeof(MessageInformation))
     {
         bus.Send(Convert(info));
     }
 }
示例#4
0
        public static string BuildExceptionMessage(this Exception exception, IMessageInformation messageInformation)
        {
            string strErrorMsg = "";
            if (messageInformation != null)
            {
                strErrorMsg += "Error in Path: " + messageInformation.Path + Environment.NewLine;

                strErrorMsg += "Raw Url: " + messageInformation.RawUrl + Environment.NewLine;
            }

            strErrorMsg += "Message: " + exception.Message + Environment.NewLine;

            strErrorMsg += "Source: " + exception.Source + Environment.NewLine;

            strErrorMsg += "Stack Trace: " + exception.StackTrace + Environment.NewLine;

            strErrorMsg += "Target Site: " + exception.TargetSite;
            return strErrorMsg;
        }
示例#5
0
 private static MessageInformation Convert(IMessageInformation info)
 {
     return(new MessageInformation
     {
         UniqueIdentifier = info.UniqueIdentifier,
         Topic = info.Topic,
         Channel = info.Channel,
         HandlerType = info.HandlerType.FullName,
         MessageType = info.MessageType.FullName,
         MessageId = info.Message.Id,
         MessageAttempt = info.Message.Attempts,
         MessageNsqdAddress = info.Message.NsqdAddress,
         MessageBody = TryGetString(info.Message.Body),
         MessageOriginalTimestamp = info.Message.Timestamp,
         Started = info.Started,
         Finished = info.Finished,
         Success = (info.Finished == null ? null : (bool?)true)
     });
 }
示例#6
0
 private static MessageInformation Convert(IMessageInformation info)
 {
     return new MessageInformation
     {
         UniqueIdentifier = info.UniqueIdentifier,
         Topic = info.Topic,
         Channel = info.Channel,
         HandlerType = info.HandlerType.FullName,
         MessageType = info.MessageType.FullName,
         MessageId = info.Message.Id,
         MessageAttempt = info.Message.Attempts,
         MessageNsqdAddress = info.Message.NsqdAddress,
         MessageBody = TryGetString(info.Message.Body),
         MessageOriginalTimestamp = info.Message.Timestamp,
         Started = info.Started,
         Finished = info.Finished,
         Success = (info.Finished == null ? null : (bool?)true)
     };
 }
示例#7
0
        public static string BuildExceptionMessage(this Exception exception, IMessageInformation messageInformation)
        {
            string strErrorMsg = "";

            if (messageInformation != null)
            {
                strErrorMsg += "Error in Path: " + messageInformation.Path + Environment.NewLine;

                strErrorMsg += "Raw Url: " + messageInformation.RawUrl + Environment.NewLine;
            }

            strErrorMsg += "Message: " + exception.Message + Environment.NewLine;

            strErrorMsg += "Source: " + exception.Source + Environment.NewLine;

            strErrorMsg += "Stack Trace: " + exception.StackTrace + Environment.NewLine;

            strErrorMsg += "Target Site: " + exception.TargetSite;
            return(strErrorMsg);
        }
示例#8
0
 public void OnSucceeded(IBus bus, IMessageInformation info)
 {
 }
示例#9
0
 public void OnReceived(IBus bus, IMessageInformation info)
 {
 }
示例#10
0
 /// <summary>
 /// Occurs when a message handler succeeds.
 /// </summary>
 /// <param name="bus">The bus.</param>
 /// <param name="info">Message information including the topic, channel, and raw message.</param>
 public void OnSucceeded(IBus bus, IMessageInformation info)
 {
 }
示例#11
0
 /// <summary>
 /// Occurs when a message is received.
 /// </summary>
 /// <param name="bus">The bus.</param>
 /// <param name="info">Message information including the topic, channel, and raw message.</param>
 public void OnReceived(IBus bus, IMessageInformation info)
 {
 }
示例#12
0
        public FailedMessageInformation(
            IMessageInformation info,
            FailedMessageQueueAction action,
            FailedMessageReason reason,
            Exception exception
        )
        {
            if (info == null)
                throw new ArgumentNullException("info");

            if (exception != null)
            {
                while (exception is TargetInvocationException && exception.InnerException != null)
                    exception = exception.InnerException;
            }

            _info = info;
            FailedAction = action;
            FailedReason = reason;
            Exception = exception;
        }
示例#13
0
 public static void DeRegisterMessage(IMessageInformation MessageInformation)
 {
     Messages.Remove(MessageInformation);
 }
示例#14
0
 public static void RegisterMessage(IMessageInformation MessageInformation)
 {
     Messages.Add(MessageInformation);
 }
示例#15
0
        private void RunTest(TestData td)
        {
            string topicName   = string.Format("{0}_{1}", td.TopicPrefix, DateTime.Now.UnixNano());
            string channelName = td.TopicPrefix;
            var    container   = new Container();

            _nsqdHttpClient.CreateTopic(topicName);
            _nsqLookupdHttpClient.CreateTopic(topicName);

            var wg = new WaitGroup();

            wg.Add(1);

            IFailedMessageInformation actualFailedMessageInfo  = null;
            IMessageInformation       actualSuccessMessageInfo = null;

            var fakeMessageAuditor = new Mock <IMessageAuditor>(MockBehavior.Strict);

            fakeMessageAuditor.Setup(p => p.OnReceived(It.IsAny <IBus>(), It.IsAny <IMessageInformation>()));
            fakeMessageAuditor.Setup(p => p.OnSucceeded(It.IsAny <IBus>(), It.IsAny <IMessageInformation>()))
            .Callback((IBus bus, IMessageInformation mi) =>
            {
                if (actualSuccessMessageInfo != null)
                {
                    throw new Exception("actualSuccessMessageInfo already set");
                }

                actualSuccessMessageInfo = mi;
                wg.Done();
            }
                      );

            fakeMessageAuditor.Setup(p => p.OnFailed(It.IsAny <IBus>(), It.IsAny <IFailedMessageInformation>()))
            .Callback((IBus bus, IFailedMessageInformation fmi) =>
            {
                if (actualFailedMessageInfo != null)
                {
                    throw new Exception("actualFailedMessageInfo already set");
                }

                actualFailedMessageInfo = fmi;
                wg.Done();
            }
                      );

            try
            {
                var nsqConfig = new Config
                {
                    LookupdPollJitter   = 0,
                    LookupdPollInterval = TimeSpan.FromMilliseconds(10),
                    DefaultRequeueDelay = TimeSpan.FromSeconds(90)
                };

                if (td.MaxAttempts != null)
                {
                    nsqConfig.MaxAttempts = td.MaxAttempts.Value;
                }

                var busConfig = new BusConfiguration(
                    new StructureMapObjectBuilder(container),
                    new NewtonsoftJsonSerializer(typeof(JsonConverter).Assembly),
                    fakeMessageAuditor.Object,
                    new MessageTypeToTopicDictionary(new Dictionary <Type, string>
                {
                    { typeof(StubMessage), topicName }
                }),
                    new HandlerTypeToChannelDictionary(new Dictionary <Type, string>
                {
                    { td.HandlerType, channelName }
                }),
                    defaultNsqLookupdHttpEndpoints: new[] { "127.0.0.1:4161" },
                    defaultThreadsPerHandler: 1,
                    nsqConfig: nsqConfig,
                    preCreateTopicsAndChannels: true
                    );

                BusService.Start(busConfig);

                var bus = container.GetInstance <IBus>();

                // send the message and wait for the WaitGroup to finish.
                bus.Send(new StubMessage());

                wg.Wait();

                Thread.Sleep(200); // wait for nsqd to process the REQ

                if (td.ExpectOnSuccess)
                {
                    Assert.IsNotNull(actualSuccessMessageInfo, "actualSuccessMessageInfo");
                }
                else
                {
                    Assert.IsNull(actualSuccessMessageInfo, "actualSuccessMessageInfo");
                }

                if (td.ExpectOnFailed)
                {
                    Assert.IsNotNull(actualFailedMessageInfo, "actualFailedMessageInfo");
                    Assert.AreEqual(td.FailedMessageReason, actualFailedMessageInfo.FailedReason, "failedReason");
                    Assert.AreEqual(td.FailedMessageQueueAction, actualFailedMessageInfo.FailedAction, "failedAction");
                }
                else
                {
                    Assert.IsNull(actualFailedMessageInfo, "actualFailedMessageInfo");
                }

                // checks stats from http server
                var stats   = _nsqdHttpClient.GetStats();
                var topic   = stats.Topics.Single(p => p.TopicName == topicName);
                var channel = topic.Channels.Single(p => p.ChannelName == channelName);

                Assert.AreEqual(1, topic.MessageCount, "topic.MessageCount");
                Assert.AreEqual(0, topic.Depth, "topic.Depth");
                Assert.AreEqual(0, topic.BackendDepth, "topic.BackendDepth");

                Assert.AreEqual(1, channel.MessageCount, "channel.MessageCount");
                // note: until the Requeue Timeout elapses the message is considered Deferred
                Assert.AreEqual(td.RequeueCount, channel.DeferredCount, "channel.DeferredCount");
                Assert.AreEqual(0, channel.Depth, "channel.Depth");
                Assert.AreEqual(0, channel.BackendDepth, "channel.BackendDepth");
                Assert.AreEqual(0, channel.InFlightCount, "channel.InFlightCount");
                Assert.AreEqual(0, channel.TimeoutCount, "channel.TimeoutCount");
                Assert.AreEqual(0, channel.RequeueCount, "channel.RequeueCount");
            }
            finally
            {
                BusService.Stop();
                _nsqdHttpClient.DeleteTopic(topicName);
                _nsqLookupdHttpClient.DeleteTopic(topicName);
            }
        }