private void Run(PairSocket shim) { m_shim = shim; shim.ReceiveReady += OnShimMessage; m_timeoutTimer = new NetMQTimer(TimeOut); m_timeoutTimer.Elapsed += OnTimeoutTimer; m_reconnectTimer = new NetMQTimer(ReconnectTimer); m_reconnectTimer.Elapsed += OnReconnectTimer; m_poller = new Poller(shim); m_poller.AddTimer(m_timeoutTimer); m_poller.AddTimer(m_reconnectTimer); shim.SignalOK(); Connect(); m_poller.PollTillCancelled(); if (m_subscriber != null) { m_subscriber.Dispose(); } }
public void Dispose() { Disconnect(); if (_reqSocket != null) { _reqSocket.Dispose(); _reqSocket = null; } if (_subSocket != null) { _subSocket.Dispose(); _subSocket = null; } if (_dealerSocket != null) { _dealerSocket.Dispose(); _dealerSocket = null; } if (_heartBeatTimer != null) { _heartBeatTimer.Dispose(); _heartBeatTimer = null; } //The context must be disposed of last! It will hang if the sockets have not been disposed. if (_context != null) { _context.Dispose(); _context = null; } }
private void RaiseHeartbeatFailed() { _currentConsumerTaskCancellation.Cancel(); _heartbeatSocket.Close(); _heartbeatSocket.Dispose(); _consumerSocket.Close(); _consumerSocket.Dispose(); }
internal void GivenTickMessage_WithSubscriber_PublishesMessage() { // Arrange var symbol = new Symbol("AUDUSD", new Venue("FXCM")); var subscriber = new SubscriberSocket(TestAddress); subscriber.Connect(TestAddress); subscriber.Subscribe($"Quote:{symbol.Value}"); Task.Delay(100).Wait(); // Allow subscribers to connect var tick = StubQuoteTickProvider.Create(symbol); // Act this.publisher.Endpoint.SendAsync(tick).Wait(); var topic = subscriber.ReceiveFrameBytes(); var message = subscriber.ReceiveFrameBytes(); // Assert Assert.Equal(1, this.publisher.SentCount); Assert.Equal("Quote:AUDUSD.FXCM", Encoding.UTF8.GetString(topic)); Assert.Equal(tick.ToSerializableString(), Encoding.UTF8.GetString(message)); // Tear Down subscriber.Disconnect(TestAddress); subscriber.Dispose(); this.publisher.Stop().Wait(); this.publisher.Dispose(); }
public void Stop() { _subscribeThreadCancellation.Cancel(); _pingThreadCancellation.Cancel(); _subscribeThread.Join(); _pingThread.Join(); _subscribeThreadCancellation.Dispose(); _pingThreadCancellation.Dispose(); lock (_publishSocketLocker) { _publishSocket?.Disconnect(_publishAddress); } _subscribeSocket?.Disconnect(_subscribeAddress); lock (_publishSocketLocker) { _publishSocket?.Dispose(); } _subscribeSocket?.Dispose(); _messageHost?.Stop(); }
public void Dispose() { _cancellationSource.Dispose(); _poller.Stop(); _poller.Dispose(); _socket.Dispose(); }
internal void GivenInstrument_WithSubscriber_PublishesMessage() { // Arrange this.publisher.Start(); Task.Delay(100).Wait(); // Allow publisher to start var instrument = StubInstrumentProvider.AUDUSD(); var subscriber = new SubscriberSocket(TestAddress); subscriber.Connect(TestAddress); subscriber.Subscribe(nameof(Instrument) + ":" + instrument.Symbol.Value); Task.Delay(100).Wait(); // Act this.publisher.Endpoint.SendAsync(instrument); var topic = subscriber.ReceiveFrameBytes(); var message = subscriber.ReceiveFrameBytes(); // Assert Assert.Equal("Instrument:AUD/USD.FXCM", Encoding.UTF8.GetString(topic)); Assert.Equal(instrument, this.instrumentSerializer.Deserialize(message)); // Tear Down subscriber.Disconnect(TestAddress); subscriber.Dispose(); this.publisher.Stop().Wait(); this.publisher.Dispose(); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { //Endpoint.RemoveNode(this); destroyed = true; foreach (OutputPlug plug in _outputs) { plug.Dispose(); } _outputs.Clear(); foreach (InputPlug plug in _inputs) { plug.Dispose(); } _inputs.Clear(); _input.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
private void Dispose(bool disposing) { if (disposing) { subSocket?.Dispose(); context?.Dispose(); } }
public void Dispose() { _actor?.Dispose(); _publisher?.Dispose(); _subscriber?.Dispose(); _beacon?.Dispose(); _poll?.Dispose(); _shim?.Dispose(); }
public void Stop() { running = false; if (sub != null) { subThread.Abort(); sub.Dispose(); } }
public void Stop() { isRunning = false; subscribeSocket.Close(); subscribeSocket.Dispose(); receiveThread.Join(100); logger.Info("Server message subscriber stopped"); }
public void Cleanup() { if (isIgniteBotEmbedded && !hasCleanedUp) { poller.StopAsync(); Thread.Sleep(10); subSocket.Dispose(); poller.Dispose(); NetMQConfig.Cleanup(false); hasCleanedUp = true; } }
protected override void Dispose() { if (!disposed) { poller.Cancel(); clientR.Dispose(); clientS.Dispose(); context.Dispose(); disposed = true; } }
/// <summary> /// This thread is needed to handle network disconnects. /// </summary> /// <remarks> /// If the PC the message host is running on disconnects from the /// network, the subscribe thread is never able to reconnect to it by /// itself. Therefore we periodically network ping the subscriber /// address to check if it responds. If it at one point does not /// respond we will need to reconnect to it again when it starts /// responding. /// </remarks> private void PingThread() { Uri uri = new Uri(_subscribeAddress); bool needsReinitialization = false; while (!_pingThreadCancellation.IsCancellationRequested) { bool pingable; Ping pinger = new Ping(); try { PingReply reply = pinger.Send(uri.Host, 1000); pingable = reply != null && (reply.Status == IPStatus.Success); } catch (PingException) { pingable = false; } if (!pingable) { needsReinitialization = true; } if (pingable && needsReinitialization) { _subscribeThreadCancellation.Cancel(); _subscribeSocket.Disconnect(_subscribeAddress); _subscribeSocket.Dispose(); _subscribeThread.Join(); _subscribeThreadCancellation = new CancellationTokenSource(); _subscribeThread = new Thread(SubscribeThread) { IsBackground = true }; _subscribeThread.Start(); while (!_subscribeThreadRunning) { Thread.Sleep(50); } needsReinitialization = false; } Thread.Sleep(5000); } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { _poller?.Dispose(); _subscriberSocket?.Dispose(); } disposedValue = true; } }
/// <summary> /// If disposing equals true, the method has been called directly or indirectly by a user's code. /// Managed and unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { _subscriberSocket?.Dispose(); _dealerSocket?.Dispose(); } _isDisposed = true; } }
private void OnTimeoutTimer(object sender, NetMQTimerEventArgs e) { // dispose the current subscriber socket and try to connect _actor.ReceiveReady -= OnActorMessage; _poller.Remove(_actor); _poller.Remove(_subscriber); _subscriber.Options.Linger = TimeSpan.Zero; _subscriber.Dispose(); _subscriber = null; Connect(); }
private void StopStationNetMQ() { // HockSocketEvents(false); try { if (null != _poller) { if (null != _subscriber) { _poller.Remove(_subscriber); } if (null != _requester) { _poller.Remove(_requester); } //_poller.Remove(_fileSubscriber); if (_poller.IsRunning) { _poller.Stop(); } _poller.Dispose(); _poller = null; } if (null != _subscriber) { _subscriber.Dispose(); _subscriber = null; } if (null != _requester) { _requester.Dispose(); _requester = null; } //_fileSubscriber.Dispose(); //_fileSubscriber = null; } catch (Exception err) { logger.ErrorFormat("Disconnect pub-sub error:{0}", err); } // this.OnDisconnected(); }
public void NetMQSubscriber_WithNullTopicDispatcher_ThrowsArgumentNullException() { // Arrange var socket = new SubscriberSocket(); // Act TestDelegate construct = () => new NetMQSubscriber(socket, messageFactory, null); // Assert Assert.That(construct, Throws.ArgumentNullException); // Cleanup socket.Dispose(); }
void OnApplicationQuit()//cleanup { SceneClient.Close(); SceneClient.Dispose(); try { ScenePoller.StopAsync(); } catch (System.Exception e) { UnityEngine.Debug.Log("Tried to stopasync while the poller wasn't running! Oops."); } ScenePoller.Dispose(); NetMQConfig.Cleanup(); }
public void Dispose() { disposing = true; MsgHandlers.Clear(); // Stop the receving thread try { if (receivingThread != null) { cts.Cancel(); receivingThread.Wait(ReceiveTimeoutMs + 50); receivingThread = null; } } catch { Log("receiving thread aborted", Logging.LogLevel.Info); } // Unsubscribe from all topics and release socket. // If receiving thread is still running when we Dispose() the socket it gets exception we catch and exit if (socket != null) { for (int i = 0; i < topics.Count; i++) { try { socket.Unsubscribe(topics[i]); } catch (Exception e) { var level = e is TerminatingException ? Logging.LogLevel.Info : Logging.LogLevel.Error; Log("terminated: " + e.Message, level); } } try { socket.Dispose(); socket = null; } catch { Log("socket dispose exception", Logging.LogLevel.Info); } } }
public void InitializeSubscriber() { if (string.IsNullOrEmpty(_configurations)) { return; } try { string[] configurations = _configurations.Split(','); _subSockets = new List <SubscriberSocket>(); foreach (var configuration in configurations) { var topicAndEnpoint = configuration.Split('|'); var subSocket = new SubscriberSocket($"tcp://{topicAndEnpoint[1]}"); subSocket.Subscribe(topicAndEnpoint[0]); _writeLog?.Invoke($"Subscriber socket connecting to {topicAndEnpoint[1]} with topic: {topicAndEnpoint[0]}\n"); subSocket.Options.ReceiveHighWatermark = 1000; _subSockets.Add(subSocket); } while (true) { _subSockets.ForEach(subSocket => { if (subSocket.TryReceiveFrameString(out string topic)) { string text = subSocket.ReceiveFrameString(); _writeLog?.Invoke($"Receiving message: Topic={topic}, Text={text};\n"); } }); _cancellationTokenSrc.Token.ThrowIfCancellationRequested(); } } catch (Exception ex) { if (!(ex is OperationCanceledException)) { _writeLog?.Invoke($"Exception handled: {ex.ToString()};\n"); } } finally { _subSockets.ForEach(subSocket => { subSocket.Dispose(); }); } }
public bool StopReceivingData() { try { NetMqPoller.Stop(); SubscriberSocket.Dispose(); SubscriberSocket = null; NetMqPoller.Dispose(); NetMqPoller = null; return(true); } catch (Exception) { return(false); } }
protected override Task DestroyInternal() { _cancel.Cancel(); _observeCacheState.Dispose(); _state.OnCompleted(); _state.Dispose(); _sourceCache.Dispose(); _cacheUpdateSocket.Close(); _cacheUpdateSocket.Dispose(); return(Task.CompletedTask); }
/// <summary> /// Dispose /// </summary> /// <returns>Returns void.</returns> public void Dispose() { m_PublisherThread.Abort(); m_SubscriberThread.Abort(); m_ResponseThread.Abort(); m_PublisherSocket.Dispose(); m_SubscriberSocket.Dispose(); m_ResponseSocket.Dispose(); m_PublisherSignal.Dispose(); m_SubAPIResponse.Clear(); m_SubAPITypeResponse.Clear(); m_RepAPIResponse.Clear(); m_RepAPITypeResponse.Clear(); }
void IDisposable.Dispose() { tokenSource.Cancel(); if (subscriber != null) { subscriber.Unsubscribe(String.Empty); subscriber.Dispose(); } if (sender != null) { sender.Dispose(); } if (context != null) { context.Dispose(); } }
private void Unregister(SubscriberSocket subscriber, List <string> topics = null) { if (topics == null) { subscriber.Close(); subscriber.Dispose(); } else { topics.ForEach(item => subscriber.Unsubscribe(item)); } if (timeout.ContainsKey(subscriber)) { timeout.Remove(subscriber); } }
internal void Test_can_publish_events() { // Arrange const string testAddress = "tcp://127.0.0.1:56601"; var publisher = new EventPublisher( this.container, new MsgPackEventSerializer(), new BypassCompressor(), EncryptionSettings.None(), new Label("test-publisher"), new Port(56601)); publisher.Start().Wait(); var subscriber = new SubscriberSocket(testAddress); subscriber.Connect(testAddress); subscriber.Subscribe("Event:Trade:TESTER-001"); Task.Delay(100).Wait(); // Allow socket to subscribe var serializer = new MsgPackEventSerializer(); var order = new StubOrderBuilder().BuildMarketOrder(); var rejected = StubEventMessageProvider.OrderRejectedEvent(order); var tradeEvent = new TradeEvent(TraderId.FromString("TESTER-001"), rejected); // Act publisher.Endpoint.Send(tradeEvent); this.Output.WriteLine("Waiting for published events..."); var topic = subscriber.ReceiveFrameBytes(); var message = subscriber.ReceiveFrameBytes(); var @event = serializer.Deserialize(message); // Assert Assert.Equal("Event:Trade:TESTER-001", Encoding.UTF8.GetString(topic)); Assert.Equal(typeof(OrderRejected), @event.GetType()); // Tear Down subscriber.Disconnect(testAddress); subscriber.Dispose(); publisher.Stop().Wait(); publisher.Dispose(); }
/// <summary> /// Cleans up resources /// </summary> private void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { TerminateConnection(); if (!(socket is null)) { socket.ReceiveReady -= OnMessageReceived; socket.Dispose(); socket = null; } } disposedValue = true; } }