コード例 #1
0
        public IDistributedMessageSubscriber GetSubscriber(CancellationToken token, ILogger logger, string channelName = null)
        {
            var ch = channelName ?? PubChannel;


            UdpVirtualSubscriber virtualSubscriber = new UdpVirtualSubscriber((s) =>
            {
                lock (_lock)
                {
                    _activeSubscribers.Remove(s);
                    _systemLogger.Trace("UDP PubSub channel {channel} removed", s.Channel);
                    if (_activeSubscribers.Count == 0)
                    {
                        _portSubscriber?.Dispose();
                        _portSubscriber = null;
                        _systemLogger.Info("UDP PubSub UDP listener closed due to empty subscribers");
                    }
                }
            }, ch);

            lock (_lock)
            {
                _activeSubscribers.Add(virtualSubscriber);

                if (_portSubscriber == null)
                {
                    _portSubscriber = new UdpPortSubscriber(_ip, _port, _systemLogger, OnUdpMessage);
                }
                _portSubscriber.StartIfNot();
            }

            return(virtualSubscriber);
        }
コード例 #2
0
 public UdpPubSubFactory(string ip, int port, IBatchLoggerFactory logger)
 {
     _ip             = ip;
     _port           = port;
     _systemLogger   = logger.GetSystemLogger();
     _portSubscriber = new UdpPortSubscriber(_ip, port, _systemLogger, OnUdpMessage);
 }