Last active
August 29, 2015 14:15
-
-
Save zshift/f86ead05796f515839e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Threading; | |
| using EasyNetQ; | |
| using EasyNetQ.ConnectionString; | |
| using EasyNetQ.Loggers; | |
| namespace EasyNetQBug | |
| { | |
| public class Program | |
| { | |
| public static void Main(String[] args) | |
| { | |
| AppDomain.CurrentDomain.UnhandledException += (sender, a) => | |
| { | |
| Console.WriteLine("Fatal Exception:\n" + a.ExceptionObject); | |
| }; | |
| var client = new RabbitClient(); | |
| client.Start(); | |
| // simulate long-running process | |
| while (true) | |
| { | |
| Thread.Sleep(5000); | |
| } | |
| } | |
| } | |
| public class RabbitClient | |
| { | |
| private IBus bus; | |
| private IDisposable responder; | |
| public void Start() | |
| { | |
| var config = ConnectionConfiguration(); | |
| bus = RabbitHutch.CreateBus(config, RegisterConsoleLogger); | |
| if (bus.IsConnected) | |
| { | |
| RegisterResponder(); | |
| } | |
| bus.Connected += RegisterResponder; | |
| bus.Disconnected += DeregisterResponder; | |
| } | |
| private void RegisterConsoleLogger(IServiceRegister serviceRegister) | |
| { | |
| serviceRegister.Register<IEasyNetQLogger>(serviceProvider => new ConsoleLogger()); | |
| } | |
| private static ConnectionConfiguration ConnectionConfiguration() | |
| { | |
| var config = new ConnectionStringParser().Parse("host=localhost"); | |
| config.VirtualHost = "/"; | |
| config.PublisherConfirms = true; | |
| config.PersistentMessages = true; | |
| config.Timeout = 5; | |
| return config; | |
| } | |
| private void RegisterResponder() | |
| { | |
| try | |
| { | |
| // If rabbit loses connection here, and this occurs twice, | |
| // EasyNetQ throws an exception from within a thread, | |
| // and the application cannot recover. | |
| responder = bus.Respond<string, string>(Respond); | |
| } | |
| catch (Exception e) | |
| { | |
| Console.WriteLine("An error occurred while responding: " + e); | |
| } | |
| } | |
| private void DeregisterResponder() | |
| { | |
| if (responder == null) return; | |
| responder.Dispose(); | |
| responder = null; | |
| } | |
| private static string Respond(string arg) | |
| { | |
| return arg + "."; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DEBUG: Trying to connect | |
| DEBUG: OnConnected event fired | |
| INFO: Connected to RabbitMQ. Broker: 'localhost', Port: 5672, VHost: '/' | |
| INFO: Disconnected from RabbitMQ Broker | |
| DEBUG: Trying to connect | |
| DEBUG: Persistent channel operation failed. Waiting for reconnection. | |
| ERROR: Failed to connect to Broker: 'localhost', Port: 5672 VHost: '/'. ExceptionMessage: 'None of the specified endpoints were reachable' | |
| ERROR: Failed to connect to any Broker. Retrying in 5000 ms | |
| ERROR: Channel action timed out. Throwing exception to client. | |
| An error occurred while responding: System.AggregateException: One or more errors occurred. ---> System.TimeoutException: The operation requested on P | |
| ersistentChannel timed out. | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelAction(Action`1 channelAction) | |
| at EasyNetQ.Producer.ClientCommandDispatcherSingleton.<>c__DisplayClass5`1.<Invoke>b__2() | |
| --- End of inner exception stack trace --- | |
| at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) | |
| at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) | |
| at System.Threading.Tasks.Task`1.get_Result() | |
| at EasyNetQ.RabbitAdvancedBus.ExchangeDeclare(String name, String type, Boolean passive, Boolean durable, Boolean autoDelete, Boolean internal, Str | |
| ing alternateExchange) | |
| at EasyNetQ.Producer.Rpc.Respond[TRequest,TResponse](Func`2 responder, Action`1 configure) | |
| at EasyNetQ.RabbitBus.RespondAsync[TRequest,TResponse](Func`2 responder, Action`1 configure) | |
| at EasyNetQ.RabbitBus.RespondAsync[TRequest,TResponse](Func`2 responder) | |
| at EasyNetQ.RabbitBus.Respond[TRequest,TResponse](Func`2 responder) | |
| at EasyNetQBug.RabbitClient.RegisterResponder() in c:\Users\peterf\Documents\Visual Studio 2013\Projects\EasyNetQBug\EasyNetQBug\Program.cs:line 70 | |
| ---> (Inner Exception #0) System.TimeoutException: The operation requested on PersistentChannel timed out. | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelAction(Action`1 channelAction) | |
| at EasyNetQ.Producer.ClientCommandDispatcherSingleton.<>c__DisplayClass5`1.<Invoke>b__2()<--- | |
| DEBUG: Trying to connect | |
| DEBUG: OnConnected event fired | |
| INFO: Disconnected from RabbitMQ Broker | |
| DEBUG: Trying to connect | |
| DEBUG: Persistent channel operation failed. Waiting for reconnection. | |
| ERROR: Failed to connect to Broker: 'localhost', Port: 5672 VHost: '/'. ExceptionMessage: 'None of the specified endpoints were reachable' | |
| ERROR: Failed to connect to any Broker. Retrying in 5000 ms | |
| ERROR: Channel action timed out. Throwing exception to client. | |
| An error occurred while responding: System.AggregateException: One or more errors occurred. ---> System.TimeoutException: The operation requested on P | |
| ersistentChannel timed out. | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelAction(Action`1 channelAction) | |
| at EasyNetQ.Producer.ClientCommandDispatcherSingleton.<>c__DisplayClass5`1.<Invoke>b__2() | |
| --- End of inner exception stack trace --- | |
| at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) | |
| at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) | |
| at System.Threading.Tasks.Task`1.get_Result() | |
| at EasyNetQ.RabbitAdvancedBus.ExchangeDeclare(String name, String type, Boolean passive, Boolean durable, Boolean autoDelete, Boolean internal, Str | |
| ing alternateExchange) | |
| at EasyNetQ.Producer.Rpc.Respond[TRequest,TResponse](Func`2 responder, Action`1 configure) | |
| at EasyNetQ.RabbitBus.RespondAsync[TRequest,TResponse](Func`2 responder, Action`1 configure) | |
| at EasyNetQ.RabbitBus.RespondAsync[TRequest,TResponse](Func`2 responder) | |
| at EasyNetQ.RabbitBus.Respond[TRequest,TResponse](Func`2 responder) | |
| at EasyNetQBug.RabbitClient.RegisterResponder() in c:\Users\peterf\Documents\Visual Studio 2013\Projects\EasyNetQBug\EasyNetQBug\Program.cs:line 70 | |
| ---> (Inner Exception #0) System.TimeoutException: The operation requested on PersistentChannel timed out. | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action`1 channelAction, DateTime startTime) | |
| at EasyNetQ.Producer.PersistentChannel.InvokeChannelAction(Action`1 channelAction) | |
| at EasyNetQ.Producer.ClientCommandDispatcherSingleton.<>c__DisplayClass5`1.<Invoke>b__2()<--- | |
| DEBUG: Trying to connect | |
| Fatal Exception: | |
| EasyNetQ.EasyNetQException: Not connected | |
| at EasyNetQ.PersistentConnection.CreateModel() | |
| at EasyNetQ.Producer.PersistentChannel.OpenChannel() | |
| at EasyNetQ.Producer.PersistentChannel.ConnectionOnConnected(ConnectionCreatedEvent event) | |
| at EasyNetQ.EventBus.Publish[TEvent](TEvent event) | |
| at EasyNetQ.PersistentConnection.OnConnected() | |
| at EasyNetQ.PersistentConnection.TryToConnect(Object timer) | |
| at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state) | |
| at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx | |
| ) | |
| at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) | |
| at System.Threading.TimerQueueTimer.CallCallback() | |
| at System.Threading.TimerQueueTimer.Fire() | |
| at System.Threading.TimerQueue.FireNextTimers() | |
| at System.Threading.TimerQueue.AppDomainTimerCallback() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment