private NSQSubscriber _getSubscriber(String shortId, String longId, String host, Int32 port, String topicName, String channelName = null) { var sub = new NSQSubscriber(shortId, longId, host, port); channelName = channelName ?? topicName; sub.Initialize(); sub.MaxReadyCount = this.MaxReadyCount; if (this.MessageHandler != null) { sub.NSQMessageRecieved += new NSQMessageRecievedHandler(this.MessageHandler); } if (this.DisconnectedHandler != null) { sub.NSQClientDisconnected += new NSQProtocolDisconnectedHandler(this.DisconnectedHandler); } Action <Object, EventArgs> defaultDisconnectedHandler = (sender, e) => { var disconnected_sub = sender as NSQSubscriber; NSQSubscriber cached_sub = null; _mappedSubscribers.TryRemove(disconnected_sub.LongIdentifier.ToLower(), out cached_sub); disconnected_sub.Dispose(); cached_sub.Dispose(); disconnected_sub = null; cached_sub = null; }; sub.NSQClientDisconnected += new NSQProtocolDisconnectedHandler(defaultDisconnectedHandler); sub.Subscribe(topicName, channelName); sub.ResetReadyCount(); return(sub); }
private NSQSubscriber _getSubscriber(String shortId, String longId, String host, Int32 port, String topicName, String channelName = null) { var sub = new NSQSubscriber(shortId, longId, host, port); channelName = channelName ?? topicName; sub.Initialize(); sub.MaxReadyCount = this.MaxReadyCount; if (this.MessageHandler != null) { sub.NSQMessageRecieved += new NSQMessageRecievedHandler(this.MessageHandler); } if (this.DisconnectedHandler != null) { sub.NSQClientDisconnected += new NSQProtocolDisconnectedHandler(this.DisconnectedHandler); } Action<Object, EventArgs> defaultDisconnectedHandler = (sender, e) => { var disconnected_sub = sender as NSQSubscriber; NSQSubscriber cached_sub = null; _mappedSubscribers.TryRemove(disconnected_sub.LongIdentifier.ToLower(), out cached_sub); disconnected_sub.Dispose(); cached_sub.Dispose(); disconnected_sub = null; cached_sub = null; }; sub.NSQClientDisconnected += new NSQProtocolDisconnectedHandler(defaultDisconnectedHandler); sub.Subscribe(topicName, channelName); sub.ResetReadyCount(); return sub; }