예제 #1
0
파일: DeviceBase.cs 프로젝트: awb99/netmq
        /// <summary>
        /// Create a new instance of the <see cref="DeviceBase"/> class.
        /// </summary>
        /// <param name="poller">the <see cref="INetMQPoller"/> to use for detecting when messages are available</param>
        /// <param name="frontendSocket">
        /// A <see cref="NetMQSocket"/> that will pass incoming messages to <paramref name="backendSocket"/>.
        /// </param>
        /// <param name="backendSocket">
        /// A <see cref="NetMQSocket"/> that will receive messages from (and optionally send replies to) <paramref name="frontendSocket"/>.
        /// </param>
        /// <param name="mode">the <see cref="DeviceMode"/> (either Blocking or Threaded) for this device</param>
        /// <exception cref="ArgumentNullException">frontendSocket must not be null.</exception>
        /// <exception cref="ArgumentNullException">backendSocket must not be null.</exception>
        protected DeviceBase(INetMQPoller poller,  NetMQSocket frontendSocket,  NetMQSocket backendSocket, DeviceMode mode)
        {
            m_isInitialized = false;

            if (frontendSocket == null)
                throw new ArgumentNullException("frontendSocket");

            if (backendSocket == null)
                throw new ArgumentNullException("backendSocket");

            FrontendSocket = frontendSocket;
            BackendSocket = backendSocket;

            FrontendSetup = new DeviceSocketSetup(FrontendSocket);
            BackendSetup = new DeviceSocketSetup(BackendSocket);

            m_poller = poller;

            FrontendSocket.ReceiveReady += FrontendHandler;
            BackendSocket.ReceiveReady += BackendHandler;

            m_poller.Add(FrontendSocket);
            m_poller.Add(BackendSocket);

            m_runner = mode == DeviceMode.Blocking
                ? new DeviceRunner(this)
                : new ThreadedDeviceRunner(this);
        }
예제 #2
0
        public void Setup()
        {
            poller         = mockPoller.Object;
            sender         = mockSender.Object;
            receiver       = mockReceiver.Object;
            publisher      = mockPublisher.Object;
            subscriber     = mockSubscriber.Object;
            pollableSocket = mockPollableSocket.Object;

            mockSender
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);

            mockReceiver
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);

            mockPublisher
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);

            mockSubscriber
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ForwarderDevice"/> class.
 /// </summary>
 /// <param name="poller">The <see cref="INetMQPoller"/> to use.</param>
 /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param>
 /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param>
 /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param>
 public ForwarderDevice(INetMQPoller poller, string frontendBindAddress, string backendBindAddress,
     DeviceMode mode = DeviceMode.Threaded)
     : base(poller, new SubscriberSocket(), new PublisherSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ForwarderDevice"/> class.
 /// </summary>
 /// <param name="poller">The <see cref="INetMQPoller"/> to use.</param>
 /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param>
 /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param>
 /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param>
 public ForwarderDevice(INetMQPoller poller, string frontendBindAddress, string backendBindAddress,
                        DeviceMode mode = DeviceMode.Threaded)
     : base(poller, new SubscriberSocket(), new PublisherSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }
예제 #5
0
        /// <summary>
        /// Create a new instance of the <see cref="DeviceBase"/> class.
        /// </summary>
        /// <param name="poller">the <see cref="INetMQPoller"/> to use for detecting when messages are available</param>
        /// <param name="frontendSocket">
        /// A <see cref="NetMQSocket"/> that will pass incoming messages to <paramref name="backendSocket"/>.
        /// </param>
        /// <param name="backendSocket">
        /// A <see cref="NetMQSocket"/> that will receive messages from (and optionally send replies to) <paramref name="frontendSocket"/>.
        /// </param>
        /// <param name="mode">the <see cref="DeviceMode"/> (either Blocking or Threaded) for this device</param>
        /// <exception cref="ArgumentNullException">frontendSocket must not be null.</exception>
        /// <exception cref="ArgumentNullException">backendSocket must not be null.</exception>
        protected DeviceBase(INetMQPoller poller, [NotNull] NetMQSocket frontendSocket, [NotNull] NetMQSocket backendSocket, DeviceMode mode)
        {
            m_isInitialized = false;

            if (frontendSocket == null)
            {
                throw new ArgumentNullException(nameof(frontendSocket));
            }

            if (backendSocket == null)
            {
                throw new ArgumentNullException(nameof(backendSocket));
            }

            FrontendSocket = frontendSocket;
            BackendSocket  = backendSocket;

            FrontendSetup = new DeviceSocketSetup(FrontendSocket);
            BackendSetup  = new DeviceSocketSetup(BackendSocket);

            m_poller = poller;

            FrontendSocket.ReceiveReady += FrontendHandler;
            BackendSocket.ReceiveReady  += BackendHandler;

            m_poller.Add(FrontendSocket);
            m_poller.Add(BackendSocket);

            m_runner = mode == DeviceMode.Blocking
                ? new DeviceRunner(this)
                : new ThreadedDeviceRunner(this);
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamerDevice"/> class.
 /// </summary>
 /// <param name="poller">The <see cref="INetMQPoller"/> to use.</param>
 /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param>
 /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param>
 /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param>
 public StreamerDevice(INetMQPoller poller, string frontendBindAddress, string backendBindAddress,
     DeviceMode mode = DeviceMode.Threaded)
     : base(poller, new PullSocket(), new PushSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamerDevice"/> class.
 /// </summary>
 /// <param name="poller">The <see cref="INetMQPoller"/> to use.</param>
 /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param>
 /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param>
 /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param>
 public StreamerDevice(INetMQPoller poller, string frontendBindAddress, string backendBindAddress,
                       DeviceMode mode = DeviceMode.Threaded)
     : base(poller, new PullSocket(), new PushSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }
예제 #8
0
파일: Proxy.cs 프로젝트: somdoron/netmq
        /// <summary>
        /// Create a new instance of a Proxy (NetMQ.Proxy)
        /// with the given sockets to serve as a front-end, a back-end, and a control socket.
        /// </summary>
        /// <param name="frontend">the socket that messages will be forwarded from</param>
        /// <param name="backend">the socket that messages will be forwarded to</param>
        /// <param name="controlIn">this socket will have incoming messages also sent to it - you can set this to null if not needed</param>
        /// <param name="controlOut">this socket will have outgoing messages also sent to it - you can set this to null if not needed</param>
        /// <param name="poller">an optional external poller to use within this proxy</param>
        public Proxy([NotNull] NetMQSocket frontend, [NotNull] NetMQSocket backend, [CanBeNull] NetMQSocket controlIn, [CanBeNull] NetMQSocket controlOut, [CanBeNull] INetMQPoller poller = null)
        {
            if (poller != null)
            {
                m_externalPoller = true;
                m_poller = poller;
            }

            m_frontend = frontend;
            m_backend = backend;
            m_controlIn = controlIn;
            m_controlOut = controlOut ?? controlIn;
        }
예제 #9
0
파일: Proxy.cs 프로젝트: liu7788414/netmq
        /// <summary>
        /// Create a new instance of a Proxy (NetMQ.Proxy)
        /// with the given sockets to serve as a front-end, a back-end, and a control socket.
        /// </summary>
        /// <param name="frontend">the socket that messages will be forwarded from</param>
        /// <param name="backend">the socket that messages will be forwarded to</param>
        /// <param name="controlIn">this socket will have incoming messages also sent to it - you can set this to null if not needed</param>
        /// <param name="controlOut">this socket will have outgoing messages also sent to it - you can set this to null if not needed</param>
        /// <param name="poller">an optional external poller to use within this proxy</param>
        public Proxy([NotNull] NetMQSocket frontend, [NotNull] NetMQSocket backend, [CanBeNull] NetMQSocket controlIn, [CanBeNull] NetMQSocket controlOut, [CanBeNull] INetMQPoller poller = null)
        {
            if (poller != null)
            {
                m_externalPoller = true;
                m_poller         = poller;
            }

            m_frontend   = frontend;
            m_backend    = backend;
            m_controlIn  = controlIn;
            m_controlOut = controlOut ?? controlIn;
        }
예제 #10
0
        /// <summary>
        /// Create a new instance of a Proxy (NetMQ.Proxy)
        /// with the given sockets to serve as a front-end, a back-end, and a control socket.
        /// </summary>
        /// <param name="frontend">the socket that messages will be forwarded from</param>
        /// <param name="backend">the socket that messages will be forwarded to</param>
        /// <param name="controlIn">this socket will have incoming messages also sent to it - you can set this to null if not needed</param>
        /// <param name="controlOut">this socket will have outgoing messages also sent to it - you can set this to null if not needed</param>
        /// <param name="poller">an optional external poller to use within this proxy</param>
        /// <param name="proxyBetween"> user provided proxy function</param>
        public NetmqProxy([NotNull] NetMQSocket frontend, [NotNull] NetMQSocket backend, [CanBeNull] NetMQSocket controlIn, [CanBeNull] NetMQSocket controlOut, [CanBeNull] INetMQPoller poller = null, Action <IReceivingSocket, IOutgoingSocket> proxyBetween = null)
        {
            if (poller != null)
            {
                m_externalPoller = true;
                m_poller         = poller;
            }

            m_frontend     = frontend;
            m_backend      = backend;
            m_controlIn    = controlIn;
            m_controlOut   = controlOut ?? controlIn;
            m_ProxyBetween = proxyBetween;
        }
예제 #11
0
        public Task StartAsync(HostingApplication hostingApplication, CancellationToken cancellationToken)
        {
            _routerSocket = new RouterSocket();
            _routerSocket.Bind($"tcp://{_hostingOptions.Host}");
            _routerSocket.ReceiveReady += RouterSocket_ReceiveReady;
            _dealerSocket = new DealerSocket();
            _dealerSocket.Bind(INPROC_SERVER_URL);
            _dealerSocket.ReceiveReady += DealerSocket_ReceiveReady;
            _poller = new NetMQPoller {
                _routerSocket, _dealerSocket
            };
            _poller.RunAsync();

            return(Task.CompletedTask);
        }
예제 #12
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            if (!connected)
            {
                socket = new SubscriberSocket(_configuration["NetMQ:SubscribeConnection"]);
                socket.Options.ReceiveHighWatermark = 1000;
                socket.Subscribe(_configuration["EventBus:Topic"]);
                socket.ReceiveReady += ReceieveMessage;
                poller = new NetMQPoller {
                    socket
                };
                poller.RunAsync();
                connected = true;
            }

            return(Task.CompletedTask);
        }
예제 #13
0
        /// <summary>
        /// Stops the proxy, blocking until the underlying <see cref="NetMQPoller"/> has completed.
        /// </summary>
        /// <exception cref="InvalidOperationException">The proxy has not been started.</exception>
        public void Stop()
        {
            if (Interlocked.CompareExchange(ref m_state, StateStopping, StateStarted) != StateStarted)
            {
                throw new InvalidOperationException("Proxy has not been started");
            }

            if (!m_externalPoller)
            {
                m_poller.Stop();
                m_poller = null;
            }

            m_frontend.ReceiveReady -= OnFrontendReady;
            m_backend.ReceiveReady  -= OnBackendReady;

            m_state = StateStopped;
        }
예제 #14
0
        private void DetachFromPoller(bool dispose)
        {
            if (m_attachedPoller == null)
            {
                throw new InvalidOperationException("Not attached to a poller");
            }

            if (dispose)
            {
                m_attachedPoller.RemoveAndDispose(m_monitoringSocket);
            }
            else
            {
                m_attachedPoller.Remove(m_monitoringSocket);
            }
            m_attachedPoller = null;
            InternalClose();
        }
예제 #15
0
        /// <summary>
        ///     Stops the proxy, blocking until the underlying <see cref="NetMQPoller" /> has completed.
        /// </summary>
        /// <exception cref="InvalidOperationException">The proxy has not been started.</exception>
        public void Stop()
        {
            if (Interlocked.CompareExchange(ref this.m_state, Proxy.StateStopping, Proxy.StateStarted) != Proxy.StateStarted)
            {
                throw new InvalidOperationException("Proxy has not been started");
            }

            if (!this.m_externalPoller)
            {
                this.m_poller.Stop();
                this.m_poller.Dispose();
                this.m_poller = null;
            }

            this.m_frontend.ReceiveReady -= this.OnFrontendReady;
            this.m_backend.ReceiveReady  -= this.OnBackendReady;

            this.m_state = Proxy.StateStopped;
        }
예제 #16
0
        /// <summary>
        ///     Start proxying messages between the front and back ends. Blocks, unless using an external
        ///     <see cref="NetMQPoller" />.
        /// </summary>
        /// <exception cref="InvalidOperationException">The proxy has already been started.</exception>
        public void Start()
        {
            if (Interlocked.CompareExchange(ref this.m_state, Proxy.StateStarting, Proxy.StateStopped) != Proxy.StateStopped)
            {
                throw new InvalidOperationException("Proxy has already been started");
            }

            this.m_frontend.ReceiveReady += this.OnFrontendReady;
            this.m_backend.ReceiveReady  += this.OnBackendReady;

            if (this.m_externalPoller)
            {
                this.m_state = Proxy.StateStarted;
            }
            else
            {
                this.m_poller = new NetMQPoller {
                    this.m_frontend, this.m_backend
                };
                this.m_state = Proxy.StateStarted;
                this.m_poller.Run();
            }
        }
예제 #17
0
파일: Proxy.cs 프로젝트: liu7788414/netmq
        /// <summary>
        /// Start proxying messages between the front and back ends. Blocks, unless using an external <see cref="NetMQPoller"/>.
        /// </summary>
        /// <exception cref="InvalidOperationException">The proxy has already been started.</exception>
        public void Start()
        {
            if (Interlocked.CompareExchange(ref m_state, StateStarting, StateStopped) != StateStopped)
            {
                throw new InvalidOperationException("Proxy has already been started");
            }

            m_frontend.ReceiveReady += OnFrontendReady;
            m_backend.ReceiveReady  += OnBackendReady;

            if (m_externalPoller)
            {
                m_state = StateStarted;
            }
            else
            {
                m_poller = new NetMQPoller {
                    m_frontend, m_backend
                };
                m_state = StateStarted;
                m_poller.Run();
            }
        }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of <see cref="NetMQMonitor"/>
 /// </summary>
 /// <param name="poller">The <see cref="INetMQPoller"/> polls the sender and receiver connections for incoming messages</param>
 public NetMQMonitor(INetMQPoller poller)
 {
     this.poller = poller ?? throw new ArgumentNullException(nameof(poller));
 }
예제 #19
0
파일: Proxy.cs 프로젝트: awb99/netmq
 /// <summary>
 /// Create a new instance of a Proxy (NetMQ.Proxy)
 /// with the given sockets to serve as a front-end, a back-end, and a control socket.
 /// </summary>
 /// <param name="frontend">the socket that messages will be forwarded from</param>
 /// <param name="backend">the socket that messages will be forwarded to</param>
 /// <param name="control">this socket will have messages also sent to it - you can set this to null if not needed</param>
 /// <param name="poller">an optional external poller to use within this proxy</param>
 /// <exception cref="InvalidOperationException"><paramref name="poller"/> is not <c>null</c> and either <paramref name="frontend"/> or <paramref name="backend"/> are not contained within it.</exception>
 public Proxy( NetMQSocket frontend,  NetMQSocket backend,  NetMQSocket control = null,  INetMQPoller poller = null)
     : this(frontend, backend, control, null, poller)
 {}
예제 #20
0
파일: Proxy.cs 프로젝트: liu7788414/netmq
 /// <summary>
 /// Create a new instance of a Proxy (NetMQ.Proxy)
 /// with the given sockets to serve as a front-end, a back-end, and a control socket.
 /// </summary>
 /// <param name="frontend">the socket that messages will be forwarded from</param>
 /// <param name="backend">the socket that messages will be forwarded to</param>
 /// <param name="control">this socket will have messages also sent to it - you can set this to null if not needed</param>
 /// <param name="poller">an optional external poller to use within this proxy</param>
 /// <exception cref="InvalidOperationException"><paramref name="poller"/> is not <c>null</c> and either <paramref name="frontend"/> or <paramref name="backend"/> are not contained within it.</exception>
 public Proxy([NotNull] NetMQSocket frontend, [NotNull] NetMQSocket backend, [CanBeNull] NetMQSocket control = null, [CanBeNull] INetMQPoller poller = null)
     : this(frontend, backend, control, null, poller)
 {
 }
예제 #21
0
 public QueueDevice(NetMQContext context, INetMQPoller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded)
     : base(poller, context.CreateRouterSocket(), context.CreateDealerSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }
예제 #22
0
파일: Proxy.cs 프로젝트: somdoron/netmq
        /// <summary>
        /// Start proxying messages between the front and back ends. Blocks, unless using an external <see cref="NetMQPoller"/>.
        /// </summary>
        /// <exception cref="InvalidOperationException">The proxy has already been started.</exception>
        public void Start()
        {
            if (Interlocked.CompareExchange(ref m_state, StateStarting, StateStopped) != StateStopped)
            {
                throw new InvalidOperationException("Proxy has already been started");
            }

            m_frontend.ReceiveReady += OnFrontendReady;
            m_backend.ReceiveReady += OnBackendReady;

            if (m_externalPoller)
            {
                m_state = StateStarted;
            }
            else
            {
                m_poller = new NetMQPoller { m_frontend, m_backend };
                m_state = StateStarted;
                m_poller.Run();
            }
        }
예제 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueDevice"/> class.
 /// </summary>
 /// <param name="poller">The <see cref="INetMQPoller"/> to use.</param>
 /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param>
 /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param>
 /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param>
 public QueueDevice(INetMQPoller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded)
     : base(poller, new RouterSocket(), new DealerSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }
예제 #24
0
파일: Proxy.cs 프로젝트: somdoron/netmq
        /// <summary>
        /// Stops the proxy, blocking until the underlying <see cref="NetMQPoller"/> has completed.
        /// </summary>
        /// <exception cref="InvalidOperationException">The proxy has not been started.</exception>
        public void Stop()
        {
            if (Interlocked.CompareExchange(ref m_state, StateStopping, StateStarted) != StateStarted)
            {
                throw new InvalidOperationException("Proxy has not been started");
            }

            if (!m_externalPoller)
            {
                m_poller.Stop();
                m_poller.Dispose();
                m_poller = null;
            }

            m_frontend.ReceiveReady -= OnFrontendReady;
            m_backend.ReceiveReady -= OnBackendReady;

            m_state = StateStopped;
        }
예제 #25
0
 /// <summary>
 /// Create a new instance of a Proxy (NetMQ.Proxy)
 /// with the given sockets to serve as a front-end, a back-end, and a control socket.
 /// </summary>
 /// <param name="frontend">the socket that messages will be forwarded from</param>
 /// <param name="backend">the socket that messages will be forwarded to</param>
 /// <param name="control">this socket will have messages also sent to it - you can set this to null if not needed</param>
 /// <param name="poller">an optional external poller to use within this proxy</param>
 /// <exception cref="InvalidOperationException"><paramref name="poller"/> is not <c>null</c> and either <paramref name="frontend"/> or <paramref name="backend"/> are not contained within it.</exception>
 public Proxy(NetMQSocket frontend, NetMQSocket backend, NetMQSocket control = null, INetMQPoller poller = null)
     : this(frontend, backend, control, null, poller)
 {
 }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueueDevice"/> class.
 /// </summary>
 /// <param name="poller">The <see cref="INetMQPoller"/> to use.</param>
 /// <param name="frontendBindAddress">The endpoint used to bind the frontend socket.</param>
 /// <param name="backendBindAddress">The endpoint used to bind the backend socket.</param>
 /// <param name="mode">The <see cref="DeviceMode"/> for the device.</param>
 public QueueDevice(INetMQPoller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded)
     : base(poller, new RouterSocket(), new DealerSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }
예제 #27
0
 public QueueDevice(NetMQContext context, INetMQPoller poller, string frontendBindAddress, string backendBindAddress, DeviceMode mode = DeviceMode.Threaded)
     : base(poller, context.CreateRouterSocket(), context.CreateDealerSocket(), mode)
 {
     FrontendSetup.Bind(frontendBindAddress);
     BackendSetup.Bind(backendBindAddress);
 }