Beispiel #1
0
 public void Dispose()
 {
     if (_forwarder != null)
     {
         _forwarder.Dispose();
         _forwarder = null;
     }
 }
Beispiel #2
0
        public ForwarderService(string frontend, string backend)
        {
            _logger.Info("Creating 0mq context.");
            _context = ZmqContext.Create();
            _logger.Info("done.");

            _logger.Info("Creating 0mq forwarder device.");
            _forwarder = new ForwarderDevice(_context, frontend, backend, DeviceMode.Threaded);
            _logger.Info("done.");

            _logger.Info("Subscribe all on frontend.");
            _forwarder.FrontendSetup.SubscribeAll();
            _logger.Info("done.");
        }
Beispiel #3
0
        public void SendOneMessageInProc()
        {
            string expectedAddress = "XXXX";
            string message = "hello its me";
            int count = 0;

            using (var context = ZmqContext.Create())
            {
                using (var forwarderDevice = new ForwarderDevice(context, "tcp://*:5555", "inproc://back", DeviceMode.Threaded))
                {
                    forwarderDevice.Start();
                    while (!forwarderDevice.IsRunning)
                    {
                        
                    }
                    using (var sub = Helper.GetConnectedSubscribeSocket(context, "inproc://back"))
                    {
                        using (var pub = Helper.GetConnectedPublishSocket(context, "tcp://localhost:5555"))
                        {

                            ZmqMessage zmqMessage = null;
                            var task = Task.Run(() =>
                                {
                                    if (sub != null)
                                    {
                                        //while (interupt != true)
                                        //{
                                            zmqMessage = Helper.ReceiveMessage(sub);
                                            //if (zmqMessage.FrameCount > 0)
                                            //{
                                            //    interupt = true;
                                            //}
                                        //}
                                    }
                                    return zmqMessage;
                                });

                            if (pub != null)
                            {
                                Helper.SendOneSimpleMessage(expectedAddress, message, pub);
                            }

                            task.Wait();
                            Assert.AreEqual(count, zmqMessage.FrameCount);
                            Frame frame = zmqMessage[0];
                            var address = Encoding.Unicode.GetString(frame.Buffer);
                            Assert.AreEqual(expectedAddress, address);
                        }
                    }
                    forwarderDevice.Stop();
                }
            }
        }