public override void UnSub(string type, string publisher, Action <byte[]> handler) { if (string.IsNullOrEmpty(type)) { throw new ArgumentNullException("type"); } if (handler == null) { throw new ArgumentNullException("handler"); } string envelope = null; if (string.IsNullOrEmpty(publisher)) { envelope = string.Concat(Global.DC_HEAD_PS_PUB, Global.ENVELOPE_SPLITTER, type); } else { envelope = string.Concat(Global.DC_HEAD_PS_PUB, Global.ENVELOPE_SPLITTER, type, Global.ENVELOPE_SPLITTER, publisher); } ConcurrentDictionary <Action <byte[]>, object> actions; if (subHands.TryGetValue(envelope, out actions)) { //((ICollection<KeyValuePair<Action<byte[]>, object>>)actions).Remove(new KeyValuePair<Action<byte[]>, object>(handler, actions[handler])); //if (actions.Count == 0) //{ // ((ICollection<KeyValuePair<string, ConcurrentDictionary<Action<byte[]>, object>>>)subHands).Remove(string, new KeyValuePair<string, ConcurrentDictionary<Action<byte[]>, object>>(envelope, subHands[envelope])); //} Thread inlineThread = new Thread(new ThreadStart(delegate() { object tempo; bool removed1 = false; while (!removed1) { removed1 = !actions.ContainsKey(handler) || actions.TryRemove(handler, out tempo); Thread.Sleep(5); } if (actions.Count == 0) { ConcurrentDictionary <Action <byte[]>, object> lst; bool removed2 = false; while (!removed2) { removed2 = !subHands.ContainsKey(envelope) || subHands.TryRemove(envelope, out lst); Thread.Sleep(5); } } System.Diagnostics.Debug.WriteLine("UnSub Thr[" + Thread.CurrentThread.Name + "] Exited."); } )); inlineThread.Start(); } clientR.Unsubscribe(Global.Encoding.GetBytes(envelope)); }
public void unsubscribeTo(byte[] topics) { for (int i = 0; i < topics.Length; i++) { byte[] topic = { (byte)'A', topics[i] }; subscriber.Unsubscribe(topic); } }
public void Unsubscribe(string topic) { if (!topics.Contains(topic)) { return; } topics.Remove(topic); socket.Unsubscribe(topic); }
public void RemoveSubscription(params string[] tickerListToRemove) { if (tickerListToRemove == null) { return; } // should probably rethink this one... each socket should have its own data. might be hitting // typical thread contention problems here. but not to worry about at the moment (ca. 2015/09/17) foreach (var ticker in tickerListToRemove) { subSocket.Unsubscribe(ticker); tickerList.Remove(ticker); } }
public void Unsubscribe() { using (var pub = new PublisherSocket()) using (var sub = new SubscriberSocket()) { int port = pub.BindRandomPort("tcp://127.0.0.1"); sub.Connect("tcp://127.0.0.1:" + port); sub.Subscribe("A"); // let the subscriber connect to the publisher before sending a message Thread.Sleep(500); pub.SendMoreFrame("A").SendFrame("Hello"); CollectionAssert.AreEqual(new[] { "A", "Hello" }, sub.ReceiveMultipartStrings()); sub.Unsubscribe("A"); Thread.Sleep(500); pub.SendMoreFrame("A").SendFrame("Hello again"); Assert.IsFalse(sub.TrySkipFrame()); } }
/// <summary> /// Cancel a live real time data stream. /// </summary> public void CancelRealTimeData(Instrument instrument) { if (!Connected) { RaiseEvent(Error, this, new ErrorArgs(-1, "Could not cancel real time data - not connected.")); return; } if (_reqSocket != null) { lock (_reqSocketLock) { //two part message: //1: "CANCEL" //2: serialized Instrument object var ms = new MemoryStream(); _reqSocket.SendMore(""); _reqSocket.SendMore("CANCEL"); _reqSocket.Send(MyUtils.ProtoBufSerialize(instrument, ms)); } } if (_subSocket != null) { _subSocket.Unsubscribe(Encoding.UTF8.GetBytes(instrument.Symbol)); } lock (_realTimeDataStreamsLock) { RealTimeDataStreams.RemoveAll(x => x.Instrument.ID == instrument.ID); } }
private void Subscriber(CancellationToken token, IObserver <TMessage> observer, ManualResetEventSlim subscribedEvent) { try { using (var socket = new SubscriberSocket()) { socket.Connect(_address); socket.Subscribe(_topic); subscribedEvent.Set(); while (!token.IsCancellationRequested) { ReceiveMessage(observer, socket); } socket.Unsubscribe(_topic); socket.Disconnect(_address); socket.Close(); } } finally { if (!subscribedEvent.IsSet) { subscribedEvent.Set(); } } }
/// <summary> /// Remove a subscription for a data feed /// </summary> /// <param name="subscriptionRequest"></param> public void RemoveSubscription(DataSubscriptionRequest subscriptionRequest) { string subscriptionname = subscriptionRequest.GetSubscriptionName(); _log.Info("Unsubscribing to subscription " + subscriptionname); if (_subscribed.Contains(subscriptionname)) { _subscribed.Remove(subscriptionname); _subscriberSocket.Unsubscribe(subscriptionname); } }
/// <summary> /// Terminates a subscription to the topic message stream /// </summary> public void Unsubscribe <TTopic>() { if (disposedValue) { throw new InvalidOperationException("NetMQSubscriber has been disposed"); } var topicName = typeof(TTopic).FullName; socket.Unsubscribe(topicName); }
public Task StopAsync(CancellationToken cancellationToken) { if (connected) { socket.Unsubscribe(_configuration["EventBus:Topic"]); socket.Disconnect(_configuration["NetMq:SubscribeConnection"]); poller.Stop(); connected = false; } return(Task.CompletedTask); }
public void MultipleSubscriptions() { using (var pub = new PublisherSocket()) using (var sub = new SubscriberSocket()) { var port = pub.BindRandomPort("tcp://127.0.0.1"); sub.Connect("tcp://127.0.0.1:" + port); sub.Subscribe("C"); sub.Subscribe("B"); sub.Subscribe("A"); sub.Subscribe("D"); sub.Subscribe("E"); Thread.Sleep(500); sub.Unsubscribe("C"); sub.Unsubscribe("B"); sub.Unsubscribe("A"); sub.Unsubscribe("D"); sub.Unsubscribe("E"); Thread.Sleep(500); } }
/// <summary> /// Cancels Subscription to the topic and closes connections. /// </summary> public void Stop() { if (Poller != null) { Poller.StopAsync(); Poller.Dispose(); Poller = null; } if (Subscriber != null) { Subscriber.ReceiveReady -= Subscriber_ReceiveReady; Subscriber.Unsubscribe(Topic); Subscriber.Disconnect("tcp://" + IP + ":" + Port.ToString()); Subscriber = null; } }
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); } }
/// <summary> /// Cancel a live real time data stream. /// </summary> public void CancelRealTimeData(Instrument instrument) { if (instrument == null) { RaiseEvent(Error, this, new ErrorArgs(-1, "Instrument cannot be null.")); return; } if (!Connected) { RaiseEvent(Error, this, new ErrorArgs(-1, "Could not cancel real time data - not connected.")); return; } lock (_realTimeRequestSocketLock) { if (_realTimeRequestSocket != null) { // Two part message: // 1: "CANCEL" // 2: serialized Instrument object _realTimeRequestSocket.SendMoreFrame(string.Empty); _realTimeRequestSocket.SendMoreFrame(MessageType.CancelRTD); using (var ms = new MemoryStream()) { _realTimeRequestSocket.SendFrame(MyUtils.ProtoBufSerialize(instrument, ms)); } } } lock (_realTimeDataSocketLock) { _realTimeDataSocket?.Unsubscribe(Encoding.UTF8.GetBytes(instrument.Symbol)); } lock (_realTimeDataStreamsLock) { RealTimeDataStreams.RemoveAll(x => x.Instrument.ID == instrument.ID); } }
/// <summary> /// unsubscribe a topic /// </summary> /// <param name="topic">topic</param> public void Unsubscribe(byte[] topic) { _Subscriber.Unsubscribe(topic); }
/// <summary> /// Unsubscribes from specified message type. /// </summary> /// <param name="messageType">Type of the message to unsubscrube.</param> public void UnsubscribeFrom(Type messageType) { _socket.Unsubscribe(_topicBuilder.GetMessageTag(_peer.Context, messageType)); }
/// <summary> /// Remove the service's subscription to the specified topic to stop receiving messages related to that topic. /// </summary> /// <param name="topic">String prefix of the topic.</param> public void Unsubscribe(string topic) { _subscriberSocket.Unsubscribe(topic); _topicsToActions.Remove(topic); }