public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { string action; if (failedInfo.FailedAction == FailedMessageQueueAction.Requeue) action = "Requeueing..."; else action = "Permanent failure."; Console.WriteLine("[{0}] {1} Message ID {2} on topic {3} channel {4} failed - {5}", DateTime.Now, action, failedInfo.Message.Id, failedInfo.Topic, failedInfo.Channel, failedInfo.Exception); }
public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { string action; if (failedInfo.FailedAction == FailedMessageQueueAction.Requeue) { action = "Requeueing..."; } else { action = "Permanent failure."; } Console.WriteLine("[{0}] {1} Message ID {2} on topic {3} channel {4} failed - {5}", DateTime.Now, action, failedInfo.Message.Id, failedInfo.Topic, failedInfo.Channel, failedInfo.Exception); }
private static MessageInformation Convert(IFailedMessageInformation 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 = false, FailedAction = info.FailedAction.ToString(), FailedReason = info.FailedReason.ToString(), FailedException = info.Exception != null?info.Exception.ToString() : null }); }
private static MessageInformation Convert(IFailedMessageInformation 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 = false, FailedAction = info.FailedAction.ToString(), FailedReason = info.FailedReason.ToString(), FailedException = info.Exception != null ? info.Exception.ToString() : null }; }
public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { if (failedInfo.MessageType != typeof(MessageInformation)) { bus.Send(Convert(failedInfo)); } else { // failed audit string logEntry = string.Format("id: {0} action:{1} reason:{2} topic:{3} channel:{4} msg:{5} ex:{6}", failedInfo.Message.Id, failedInfo.FailedAction, failedInfo.FailedReason, failedInfo.Topic, failedInfo.Channel, Encoding.UTF8.GetString(failedInfo.Message.Body), failedInfo.Exception); if (failedInfo.FailedAction == FailedMessageQueueAction.Requeue) { Trace.TraceWarning(logEntry); } else { Trace.TraceError(logEntry); } } }
public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { Trace.TraceError(failedInfo.Exception.ToString()); }
/// <summary> /// Occurs when a message handler fails. /// </summary> /// <param name="bus">The bus.</param> /// <param name="failedInfo">Message information including the topic, channel, and raw message.</param> public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { Console.WriteLine(failedInfo.Exception); }
public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { }
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); } }
/// <summary> /// Occurs when a message handler fails. /// </summary> /// <param name="bus">The bus.</param> /// <param name="failedInfo">Message information including the topic, channel, and raw message.</param> public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { //Log.Info(failedInfo.Exception); }
public void OnFailed(IBus bus, IFailedMessageInformation failedInfo) { Console.Error?.WriteLine(failedInfo.Exception.ToString()); }