Beispiel #1
0
        private void RunActor(PairSocket shim)
        {
            _shim = shim;

            using (_subscriber = new SubscriberSocket())
                using (_publisher = new PublisherSocket())
                {
                    using (_beacon = new NetMQBeacon())
                    {
                        _shim.ReceiveReady += OnShimReady;

                        _subscriber.Subscribe(string.Empty);
                        _port = _subscriber.BindRandomPort("tcp://*");
                        _logger?.LogInformation($"{_id}: Peer bus is bound to {{BusPort}}", _port);
                        _subscriber.ReceiveReady += OnSubscriberReady;

                        _logger?.LogInformation($"{_id}: Peer is broadcasting UDP on port {{BeaconPort}}", _beaconPort);
                        _beacon.Configure(_beaconPort);
                        _beacon.Publish(_port.ToString(), _beaconInterval);
                        _beacon.Subscribe(string.Empty);
                        _beacon.ReceiveReady += OnBeaconReady;

                        var cleanupTimer = new NetMQTimer(_cleanupInterval);
                        cleanupTimer.Elapsed += Cleanup;

                        _poll = new NetMQPoller {
                            _shim, _subscriber, _beacon, cleanupTimer
                        };
                        _shim.SignalOK();
                        _poll.Run();
                    }
                }
        }
Beispiel #2
0
        private void RunActor(PairSocket shim)
        {
            // save the shim to the class to use later
            m_shim = shim;

            // create all subscriber, publisher and beacon
            using (m_subscriber = new SubscriberSocket())
                using (m_publisher = new PublisherSocket())
                    using (m_beacon = new NetMQBeacon())
                    {
                        // listen to actor commands
                        m_shim.ReceiveReady += OnShimReady;

                        // subscribe to all messages
                        m_subscriber.Subscribe("");

                        // we bind to a random port, we will later publish this port
                        // using the beacon
                        m_randomPort = m_subscriber.BindRandomPort("tcp://*");
                        Console.WriteLine("Bus subscriber is bound to {0}", m_subscriber.Options.LastEndpoint);

                        // listen to incoming messages from other publishers, forward them to the shim
                        m_subscriber.ReceiveReady += OnSubscriberReady;

                        // configure the beacon to listen on the broadcast port
                        Console.WriteLine("Beacon is being configured to UDP port {0}", m_broadcastPort);
                        m_beacon.Configure(m_broadcastPort);

                        // publishing the random port to all other nodes
                        Console.WriteLine("Beacon is publishing the Bus subscriber port {0}", m_randomPort);
                        m_beacon.Publish(m_randomPort.ToString(), TimeSpan.FromSeconds(1));

                        // Subscribe to all beacon on the port
                        Console.WriteLine("Beacon is subscribing to all beacons on UDP port {0}", m_broadcastPort);
                        m_beacon.Subscribe("");

                        // listen to incoming beacons
                        m_beacon.ReceiveReady += OnBeaconReady;

                        // Create a timer to clear dead nodes
                        NetMQTimer timer = new NetMQTimer(TimeSpan.FromSeconds(1));
                        timer.Elapsed += ClearDeadNodes;

                        // Create and configure the poller with all sockets and the timer
                        m_poller = new NetMQPoller {
                            m_shim, m_subscriber, m_beacon, timer
                        };

                        // signal the actor that we finished with configuration and
                        // ready to work
                        m_shim.SignalOK();

                        // polling until cancelled
                        m_poller.Run();
                    }
        }
Beispiel #3
0
        private void RunActor(PairSocket shim)
        {
            // save the shim to the class to use later
            m_shim = shim;

            // create all subscriber, publisher and beacon
            using (m_subscriber = new SubscriberSocket())
            using (m_publisher = new PublisherSocket())
            using (m_beacon = new NetMQBeacon())
            {
                // listen to actor commands
                m_shim.ReceiveReady += OnShimReady;

                // subscribe to all messages
                m_subscriber.Subscribe("");

                // we bind to a random port, we will later publish this port
                // using the beacon
                m_randomPort = m_subscriber.BindRandomPort("tcp://*");
                Console.WriteLine("Bus subscriber is bound to {0}", m_subscriber.Options.LastEndpoint);

                // listen to incoming messages from other publishers, forward them to the shim
                m_subscriber.ReceiveReady += OnSubscriberReady;

                // configure the beacon to listen on the broadcast port
                Console.WriteLine("Beacon is being configured to UDP port {0}", m_broadcastPort);
                m_beacon.Configure(m_broadcastPort);

                // publishing the random port to all other nodes
                Console.WriteLine("Beacon is publishing the Bus subscriber port {0}", m_randomPort);
                m_beacon.Publish(m_randomPort.ToString(), TimeSpan.FromSeconds(1));

                // Subscribe to all beacon on the port
                Console.WriteLine("Beacon is subscribing to all beacons on UDP port {0}", m_broadcastPort);
                m_beacon.Subscribe("");

                // listen to incoming beacons
                m_beacon.ReceiveReady += OnBeaconReady;

                // Create a timer to clear dead nodes
                NetMQTimer timer = new NetMQTimer(TimeSpan.FromSeconds(1));
                timer.Elapsed += ClearDeadNodes;

                // Create and configure the poller with all sockets and the timer
                m_poller = new NetMQPoller { m_shim, m_subscriber, m_beacon, timer };

                // signal the actor that we finished with configuration and
                // ready to work
                m_shim.SignalOK();

                // polling until cancelled
                m_poller.Run();
            }
        }