Ejemplo n.º 1
0
        public void Start()
        {
            ManualResetEvent mre = new ManualResetEvent(false);

            // NetMQ.Bind to Publish and Subscribe addresses
            Task.Factory.StartNew(() =>
            {
                using (_toSocket = new XPublisherSocket())
                    using (_fromSocket = new XSubscriberSocket())
                    {
                        _toSocket.Bind(_toAddress);
                        _fromSocket.Bind(_fromAddress);

                        _proxy = new Proxy(_fromSocket, _toSocket);

                        mre.Set();

                        // This method is blocking, so important to set the ManualResetEvent before this.
                        _proxy.Start();
                    }
            });

            // Wait until the message host is actually started before returning
            mre.WaitOne(-1);
        }
Ejemplo n.º 2
0
        private void ProxyThread()
        {
            if (_disposeCount != 0)
            {
                _traces.Debug("IpcEventProxy: disposed before start.");
                return;
            }
            XSubscriberSocket xsub = null;
            XPublisherSocket  xpub = null;

            try
            {
                xsub = _context.CreateXSubscriberSocket();
                xpub = _context.CreateXPublisherSocket();

                xsub.Bind(_xSubscriberAddress);
                xpub.Bind(_xPublisherAddress);
                var xproxy = new Proxy(xpub, xsub, null);
                _traces.Debug("IpcEventProxy: started (pub->xsub {0} <=> {1} xpub<-sub)", _xSubscriberAddress, _xPublisherAddress);
                xproxy.Start();
                _traces.Debug("IpcEventProxy: stopped.");
            }
            catch (NetMQException ex)
            {
                if (_disposeCount == 0 && !(ex is TerminatingException))
                {
                    _isFaultedState = true;
                    _traces.Error(ex, "Error while IpcEventProxy starting or during operation.");
                    var handler = FaultedState;
                    if (handler != null)
                    {
                        try
                        {
                            handler(this, EventArgs.Empty);
                        }
                        catch (Exception ex2)
                        {
                            _traces.Error(ex2);
                        }
                    }
                }
            }
            finally
            {
                if (xsub != null)
                {
                    _traces.CaptureMqExceptions(xsub.Dispose);
                }
                if (xpub != null)
                {
                    _traces.CaptureMqExceptions(xpub.Dispose);
                }
            }
        }
Ejemplo n.º 3
0
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            xpubSocket.Bind(BusOption.SubscriberAddress);
            xsubSocket.Bind(BusOption.PublisherAddress);

            this.logger.LogInformation("MQBusService started");

            var proxy = new Proxy(xsubSocket, xpubSocket);

            return(Task.Run(proxy.Start));
        }
Ejemplo n.º 4
0
        private void Work()
        {
            using (var subscriberSocket = new XSubscriberSocket())
            {
                subscriberSocket.Bind(_toPublisherEndpoint);

                using (var publisherSocket = new XPublisherSocket())
                {
                    publisherSocket.Bind(_toSubscriberEndpoint);

                    _proxy = new Proxy(subscriberSocket, publisherSocket);
                    _proxy.Start();
                }
            }
        }