Ejemplo n.º 1
0
 public static void Main(string[] args)
 {
     using (var context = ZmqContext.Create())
     {
         using (var queue = new ZeroMQ.Devices.QueueDevice(context, "tcp://*:5555", "inproc://workers", DeviceMode.Blocking))
         {
             queue.Initialize();
             var workerThreads = new Thread[5];
             for (int threadId = 0; threadId < workerThreads.Length; threadId++)
             {
                 workerThreads[threadId] = new Thread(WorkerRoutine);
                 workerThreads[threadId].Start(context);
             }
             queue.Start();
         }
     }
 }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            using (var context = ZmqContext.Create())
            {

                using (var queue = new ZeroMQ.Devices.QueueDevice(context, "tcp://*:5555", "inproc://workers", DeviceMode.Blocking))
                {
                    queue.Initialize();
                    var workerThreads = new Thread[5];
                    for (int threadId = 0; threadId < workerThreads.Length; threadId++)
                    {
                        workerThreads[threadId] = new Thread(WorkerRoutine);
                        workerThreads[threadId].Start(context);
                    }
                    queue.Start();
                }

            }
        }
Ejemplo n.º 3
0
Archivo: Pipe.cs Proyecto: nka1/Daytona
        public void Start(ZmqContext context)
        {
            this.SetUpMonitorChannel(context);
            this.SetUpAddSubscriberCountChannel(context);

            ////this should work but the forwarder device appears to be broken - it does not use XSUb and XPUB sockets
            ////ForwarderDevice = new ForwarderDevice(context, PublishAddressServer, SubscribeAddressServer, DeviceMode.Threaded);
            ////ForwarderDevice.Start();
            ////while (!ForwarderDevice.IsRunning)
            ////{ }

            QueueDevce = new QueueDevice(context, PubSubControlBackAddressServer, PubSubControlFrontAddress, DeviceMode.Threaded);
            QueueDevce.Start();
            while (!QueueDevce.IsRunning)
            {
            }

            this.Writeline("Control channel started");

            //this.Context = context;
            this.cancellationTokenSource = new CancellationTokenSource();
            var token = this.cancellationTokenSource.Token;
            Task.Run(() =>
            {
                using (frontend = context.CreateSocket(SocketType.XSUB))
                {
                    using (backend = context.CreateSocket(SocketType.XPUB))
                    {
                        frontend.Bind(Pipe.PublishAddressServer); ////"tcp://*:5550");
                        backend.Bind(Pipe.SubscribeAddressServer); ////"tcp://*:5553");
                        frontend.ReceiveReady += new EventHandler<SocketEventArgs>(FrontendReceiveReady);
                        backend.ReceiveReady += new EventHandler<SocketEventArgs>(BackendReceiveReady);
                        this.AddSubscriberCountChannel.ReceiveReady += new EventHandler<SocketEventArgs>(AddSubscriberCountChannelReceiveReady);
                        using (poller = new Poller(new ZmqSocket[] { frontend, backend, this.AddSubscriberCountChannel }))
                        {
                            Writeline("About to start polling");

                            while (true)
                            {
                                poller.Poll(new TimeSpan(0,0,0,0,5));
                                Writeline("polling");
                                if (token.IsCancellationRequested)
                                {
                                    Writeline("break");
                                    break;
                                }
                            }
                        }

                        Writeline("stopped polling and exiting");
                    }
                }
            },
            token);
        }