Start() public method

Start proxying messages between the front and back ends. Blocks, unless using an external NetMQPoller.
The proxy has already been started.
public Start ( ) : void
return void
Esempio n. 1
0
        /// <summary>
        /// Starts the local to external message transfering.
        /// </summary>
        /// <param name="proxyForPublishersPort">The port for local publishers.</param>
        /// <param name="busPublisherPort">Broker's publisher port for other brokers subscription.</param>
        private void StartLocalToExternalTransfer(int proxyForPublishersPort, int busPublisherPort)
        {
            Task.Run(() =>
            {
                using (var subSocket = new SubscriberSocket())
                    using (var pubSocket = new PublisherSocket())
                    {
                        subSocket.SubscribeToAnyTopic();
                        subSocket.Bind($"tcp://localhost:{proxyForPublishersPort}");

                        pubSocket.Bind($"tcp://localhost:{busPublisherPort}");

                        _localToExternalProxy = new NetMQ.Proxy(subSocket, pubSocket);

                        _localToExternalProxy.Start();
                    }
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Starts the external to local message transfering.
        /// </summary>
        /// <param name="portForSubscribers">The port for local subscribers.</param>
        /// <param name="discoveryEndpoints">The endpoints to perform other brokers discovery.</param>
        private void StartExternalToLocalTransfer(int portForSubscribers, EndpointsRange discoveryEndpoints)
        {
            Task.Run(() =>
            {
                using (var xsubSocket = new XSubscriberSocket())
                    using (var xpubSocket = new XPublisherSocket())
                    {
                        xpubSocket.Bind($"tcp://localhost:{portForSubscribers}");

                        var dynamicSubscriber = new DynamicSubscriber(xsubSocket, discoveryEndpoints);
                        dynamicSubscriber.StartDiscovering();

                        _externalToLocalProxy = new NetMQ.Proxy(xpubSocket, xsubSocket);

                        _externalToLocalProxy.Start();
                    }
            });
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            //
            // Simple request-reply broker
            //
            // Author: metadings
            //

            // Prepare our context and sockets
            using (var ctx = NetMQContext.Create())
            using (var frontend = ctx.CreateRouterSocket())
            using (var backend = ctx.CreateDealerSocket())
            {
                frontend.Bind("tcp://*:5559");
                backend.Bind("tcp://*:5560");

                var proxy = new Proxy(frontend, backend);
                proxy.Start();
            }
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            //
            // Weather proxy device
            //
            // Author: metadings
            //

            using (var context = NetMQContext.Create())
            using (var frontend = context.CreateXSubscriberSocket())
            using (var backend = context.CreateXPublisherSocket())
            {
                // Frontend is where the weather server sits
                const string localhost = "tcp://127.0.0.1:5556";
                Console.WriteLine("I: Connecting to {0}", localhost);
                frontend.Connect(localhost);

                // Backend is our public endpoint for subscribers
                foreach (var address in WUProxy_GetPublicIPs())
                {
                    var tcpAddress = string.Format("tcp://{0}:8100", address);
                    Console.WriteLine("I: Binding on {0}", tcpAddress);
                    backend.Bind(tcpAddress);

                    var epgmAddress = string.Format("epgm://{0};239.192.1.1:8100", address);
                    Console.WriteLine("I: Binding on {0}", epgmAddress);
                    backend.Bind(epgmAddress);
                }

                backend.SendFrame(new byte[] { 0x1 });

                // Run the proxy until the user interrupts us
                var proxy = new Proxy(frontend, backend);
                proxy.Start();
            }
        }
Esempio n. 5
0
 static void Main(string[] args)
 {
     NetMQ.Proxy proxy = new NetMQ.Proxy(new XSubscriberSocket("@tcp://*:1011"), new XPublisherSocket("@tcp://*:1012"));
     Console.WriteLine("running...");
     proxy.Start();
 }
Esempio n. 6
0
        public void Evaluate(int SpreadMax)
        {
            if (FFrontendSocket.SliceCount == 0 || (FFrontendSocket.SliceCount == 1 && FFrontendSocket[0] == null) ||
                FBackendSocket.SliceCount == 0 || (FBackendSocket.SliceCount == 1 && FBackendSocket[0] == null))
            {
                return;
            }

            if (FEnable.IsChanged && !FEnable[0])
            {
                foreach (var p in Proxies)
                {
                    try
                    {
                        p.Stop();
                    }
                    catch (InvalidOperationException e)
                    {
                        FLogger.Log(LogType.Warning, "\nvvvv.ZeroMQ: Proxy cannot be stopped. " + e.Message);
                    }
                }

            }

            // spreading could cause weird behaviour, when multiple proxies feed on the same sockets
            SpreadMax = FFrontendSocket.CombineWith(FBackendSocket);

            for (int i = 0; i < SpreadMax; i++)
            {
                var backend = (NetMQSocket)FBackendSocket[i];
                var frontend = (NetMQSocket)FFrontendSocket[i];

                if (frontend == null || backend == null)
                {
                    continue;
                }

                if (FEnable.IsChanged && FEnable[i])
                {

                    // FRONTEND
                    try
                    {
                        Poll.Add(frontend);
                    }
                    catch (ArgumentException)
                    {
                        FLogger.Log(LogType.Message, "\nvvvv.ZeroMQ: Socket already added to Poller in Proxy. Nothing to worry about.");
                    }
                    catch (ObjectDisposedException)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: Cannot add Socket to Proxy, already disposed.");
                    }

                    // BACKEND
                    try
                    {
                        Poll.Add(backend);
                    }
                    catch (ArgumentException)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: Socket already added to Poller in Proxy. Nothing to worry about.");
                    }
                    catch (ObjectDisposedException)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: Cannot add Socket to Proxy, already disposed.");
                    }

                    // PROXY
                    try
                    {
                        var p = new Proxy(frontend, backend, null, Poll);
                        p.Start(); // nonblocking from now on

                        Proxies.Add(p);
                    }
                    catch (InvalidOperationException e)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: start Proxy failed.\n"+e);
                    }
                }
            }
        }