public void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); ChannelId = "ChannelId"; UnderlyingMessaging = new SynchronousMessagingSystemFactory(); MessagingSystemFactory = new MonitoredMessagingFactory(UnderlyingMessaging, TimeSpan.FromMilliseconds(250), TimeSpan.FromMilliseconds(750)); }
public void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); ChannelId = "tcp://127.0.0.1:7080/"; UnderlyingMessaging = new TcpMessagingSystemFactory(); MessagingSystemFactory = new MonitoredMessagingFactory(UnderlyingMessaging, TimeSpan.FromMilliseconds(250), // e.g. if the communication is very intensive then it may take more time until the response is received. TimeSpan.FromMilliseconds(750)); }
public void Setup() { //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug; //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt"); ChannelId = "Channel_1"; UnderlyingMessaging = new SynchronousMessagingSystemFactory(); TimeSpan aPingFrequency = TimeSpan.FromMilliseconds(50); TimeSpan aPingResponseTimeout = TimeSpan.FromMilliseconds(500); MessagingSystem = new MonitoredMessagingFactory(UnderlyingMessaging, aPingFrequency, aPingResponseTimeout); }
/// <summary> /// Constructs the factory with the specified parameters. /// </summary> /// <param name="underlyingMessaging">underlying messaging system e.g. TCP</param> /// <param name="maxOfflineTime">the maximum time, the messaging can work offline. When the messaging works offline, /// the sent messages are buffered and the connection is being reopened. If the connection is /// not reopen within maxOfflineTime, the connection is closed. /// </param> /// <param name="pingFrequency">how often the connection is checked with the 'ping' requests.</param> /// <param name="pingResponseTimeout">the maximum time, the response for the 'ping' is expected.</param> public BufferedMonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging, // Buffered Messaging TimeSpan maxOfflineTime, // Monitored Messaging TimeSpan pingFrequency, TimeSpan pingResponseTimeout) { using (EneterTrace.Entering()) { myMonitoredMessaging = new MonitoredMessagingFactory(underlyingMessaging, pingFrequency, pingResponseTimeout); myBufferedMessaging = new BufferedMessagingFactory(myMonitoredMessaging, maxOfflineTime); } }
public void A02_Reconnect_StopListening() { MonitoredMessagingFactory aConnectionMonitor = new MonitoredMessagingFactory(MessagingSystemFactory); IDuplexInputChannel aDuplexInputChannel = aConnectionMonitor.CreateDuplexInputChannel(ChannelId); IDuplexOutputChannel aDuplexOutputChannel = aConnectionMonitor.CreateDuplexOutputChannel(ChannelId); // Max 5 attempts to try to reconnect. Reconnecter aReconnecter = new Reconnecter(aDuplexOutputChannel, TimeSpan.FromMilliseconds(300), 5); AutoResetEvent aReconnectEvent = new AutoResetEvent(false); DuplexChannelEventArgs aReconnectEventArgs = null; aReconnecter.ConnectionOpened += (x, y) => { aReconnectEventArgs = y; aReconnectEvent.Set(); }; AutoResetEvent aDisconnectEvent = new AutoResetEvent(false); DuplexChannelEventArgs aDisconnectEventArgs = null; aReconnecter.ConnectionClosed += (x, y) => { aDisconnectEventArgs = y; aDisconnectEvent.Set(); }; AutoResetEvent aReconnecFailedEvent = new AutoResetEvent(false); DuplexChannelEventArgs aReconnectingFailedEventArgs = null; aReconnecter.ReconnectingFailed += (x, y) => { aReconnectingFailedEventArgs = y; aReconnecFailedEvent.Set(); }; try { aReconnecter.EnableReconnecting(); // Start listening. aDuplexInputChannel.StartListening(); aDuplexOutputChannel.OpenConnection(); Thread.Sleep(2000); Assert.IsTrue(aDuplexOutputChannel.IsConnected); Assert.IsNull(aReconnectingFailedEventArgs); Assert.IsNull(aDisconnectEventArgs); Assert.IsNull(aReconnectEventArgs); // Stop listening. // Note: The Reconnecter will try 5 times to reopen the connection, then it will notify, the reconnecion failed. aDuplexInputChannel.StopListening(); // Wait until the disconnect is notified. aDisconnectEvent.WaitOne(); Assert.AreEqual(aDuplexOutputChannel.ChannelId, aDisconnectEventArgs.ChannelId); Assert.AreEqual(aDuplexOutputChannel.ResponseReceiverId, aDisconnectEventArgs.ResponseReceiverId); Assert.IsFalse(aDuplexOutputChannel.IsConnected); Assert.IsNull(aReconnectEventArgs); // Wait until the reconnect fails after 5 failed reconnects. aReconnecFailedEvent.WaitOne(); Assert.AreEqual(aDuplexOutputChannel.ChannelId, aReconnectingFailedEventArgs.ChannelId); Assert.AreEqual(aDuplexOutputChannel.ResponseReceiverId, aReconnectingFailedEventArgs.ResponseReceiverId); Assert.IsFalse(aDuplexOutputChannel.IsConnected); Assert.IsNull(aReconnectEventArgs); } finally { aDuplexOutputChannel.CloseConnection(); aDuplexInputChannel.StopListening(); aReconnecter.DisableReconnecting(); } }