CreatePushSocket() private method

private CreatePushSocket ( ) : PushSocket
return PushSocket
Ejemplo n.º 1
0
        private bool _disposedValue = false; // Для определения избыточных вызовов

        #endregion Fields

        #region Constructors

        public FanBrocker(NetMQContext context, string ventAddress, string sinkAddress, int workersCnt)
        {
            _logger.Trace("Brocker created");
            _ventAddress = ventAddress;
            _sinkAddress = sinkAddress;

            _sinkSocket = context.CreatePullSocket();
            _sinkSocket.Options.ReceiveBuffer = 1;

            _sinkSocket.Bind(sinkAddress);

            _ventSocket = context.CreatePushSocket();
            _ventSocket.Options.SendBuffer = 1;
            _ventSocket.Bind(ventAddress);

            Task.Run(() =>
            {
                try
                {
                    while (true)
                    {
                        var ba = _sinkSocket.ReceiveFrameString();
                        _logger.Trace("Brocker received data {0}", ba);
                        var data = JsonConvert.DeserializeObject<ProcessedEventArgs>(ba);
                        OnFramesProcessed(data);
                    }
                }
                catch (Exception)
                {

                    _logger.Error("EXCEPTION");
                }

            });
        }
Ejemplo n.º 2
0
 public NetMQWorker(int id, string pushAddress, string pullAddress, NetMQContext context) : base(id)
 {
     _pullSocket = context.CreatePullSocket();
     _pushSocket = context.CreatePushSocket();
     _pushSocket.Connect(pushAddress);
     _pullSocket.Bind(pullAddress+id);
 }
Ejemplo n.º 3
0
 public FeedZmQPublisher(string address, ILog log)
 {
     _log = log;
     _context = NetMQContext.Create();
     _socket = _context.CreatePushSocket();
     _socket.Bind(address);
 }
        public void Start(string serverIpAddress, int serverPort)
        {
            ctx = NetMQContext.Create();
            pushSocket = ctx.CreatePushSocket();

            string serverAddress = string.Format("tcp://{0}:{1}", serverIpAddress, serverPort);
            pushSocket.Connect(serverAddress);
        }
Ejemplo n.º 5
0
		public CommandListener (int port, Dictionary<int, Job> jobs)
		{
			this.Port = port;
			this.Jobs = jobs;
			this.Context = NetMQContext.Create ();
			this.RequestSock = Context.CreateResponseSocket ();
			this.RequestSock.Bind ("tcp://0.0.0.0:" + Port);
			logger.Info ("Bound to TCP port {0}", Port);

			this.ResponseSock = Context.CreatePushSocket ();
			this.ResponseSock.Bind ("tcp://0.0.0.0:" + (Port + 1));
			logger.Info ("Bound callback to TCP port {0}", (Port + 1));
		}
Ejemplo n.º 6
0
        public NetMQScheduler(NetMQContext context, Poller poller = null)
        {
            m_context = context;
            if (poller == null)
            {
                m_ownPoller = true;

                m_poller = new Poller();
            }
            else
            {
                m_ownPoller = false;

                m_poller = poller;
            }

            m_clientSockets = new ConcurrentBag <NetMQSocket>();

            m_schedulerId = Interlocked.Increment(ref s_schedulerCounter);

            m_address = string.Format("{0}://scheduler-{1}", NetMQ.zmq.Address.InProcProtocol, m_schedulerId);

            m_serverSocket = context.CreatePullSocket();
            m_serverSocket.Options.Linger = TimeSpan.Zero;
            m_serverSocket.Bind(m_address);

            m_currentMessageHandler = OnMessageFirstTime;

            m_serverSocket.ReceiveReady += m_currentMessageHandler;

            m_poller.AddSocket(m_serverSocket);

            m_clientSocket = new ThreadLocal <NetMQSocket>(() =>
            {
                var socket = m_context.CreatePushSocket();
                socket.Connect(m_address);

                m_clientSockets.Add(socket);

                return(socket);
            });

            m_schedulerThread = new ThreadLocal <bool>(() => false);

            if (m_ownPoller)
            {
                Task.Factory.StartNew(m_poller.Start, TaskCreationOptions.LongRunning);
            }
        }
Ejemplo n.º 7
0
        public NetMQScheduler(NetMQContext context, Poller poller = null)
        {
            m_context = context;
            if (poller == null)
            {
                m_ownPoller = true;

                m_poller = new Poller();
            }
            else
            {
                m_ownPoller = false;

                m_poller = poller;
            }

            m_clientSockets = new ConcurrentBag<NetMQSocket>();

            m_schedulerId = Interlocked.Increment(ref s_schedulerCounter);

            m_address = string.Format("{0}://scheduler-{1}", NetMQ.zmq.Address.InProcProtocol, m_schedulerId);

            m_serverSocket = context.CreatePullSocket();
            m_serverSocket.Options.Linger = TimeSpan.Zero;
            m_serverSocket.Bind(m_address);

            m_currentMessageHandler = OnMessageFirstTime;

            m_serverSocket.ReceiveReady += m_currentMessageHandler;

            m_poller.AddSocket(m_serverSocket);

            m_clientSocket = new ThreadLocal<NetMQSocket>(() =>
                    {
                        var socket = m_context.CreatePushSocket();
                        socket.Connect(m_address);

                        m_clientSockets.Add(socket);

                        return socket;
                    });

            m_schedulerThread = new ThreadLocal<bool>(() => false);

            if (m_ownPoller)
            {
                Task.Factory.StartNew(m_poller.Start, TaskCreationOptions.LongRunning);
            }
        }
Ejemplo n.º 8
0
        private bool _disposedValue = false; // Для определения избыточных вызовов

        #endregion Fields

        #region Constructors

        public NetMQBrocker(NetMQContext context, string pushAddress, string pullAddress, int workersCnt)
        {
            _logger.Trace("Brocker created");
            _pushAddress = pushAddress;
            _pullAddress = pullAddress;

            //_pushSocket.Bind(pushAddress);
            _pullSocket = context.CreatePullSocket();
            _pullSocket.Bind(pullAddress);

            _pushSocket = context.CreatePushSocket();

            Task.Run(() =>
            {
                try
                {

                    while (true)
                    {
                        var ba = _pullSocket.ReceiveFrameBytes();
                        if (ba != null)
                        {

                            using (var ms = new MemoryStream())
                            {
                                ms.Write(ba, 0, ba.Length);
                                ms.Position = 0;
                                var data = (ProcessedEventArgs)_formatter.Deserialize(ms);
                                _logger.Trace("Brocker received result queue {0}", data.QueueId);
                                OnFramesProcessed(data);
                            }
                        }
                        else
                        {
                            _logger.Trace("Brocker not received");
                            Thread.Sleep(200);
                        }
                    }
                }
                catch (Exception)
                {

                    _logger.Error("EXCEPTION");
                }

            });
        }
Ejemplo n.º 9
0
        public NetMQScheduler(NetMQContext context, Poller poller = null)
        {
            m_context = context;
            if (poller == null)
            {
                m_ownPoller = true;
                m_poller    = new Poller();
            }
            else
            {
                m_ownPoller = false;
                m_poller    = poller;
            }

            m_tasksQueue = new ConcurrentQueue <Task>();
            m_syncObject = new object();

            m_schedulerId = Interlocked.Increment(ref s_schedulerCounter);

            m_address = string.Format("{0}://scheduler-{1}", NetMQ.zmq.Address.InProcProtocol, m_schedulerId);

            m_serverSocket = context.CreatePullSocket();
            m_serverSocket.Options.Linger = TimeSpan.Zero;
            m_serverSocket.Bind(m_address);

            m_currentMessageHandler = OnMessageFirstTime;

            m_serverSocket.ReceiveReady += m_currentMessageHandler;

            m_poller.AddSocket(m_serverSocket);

            m_clientSocket = m_context.CreatePushSocket();
            m_clientSocket.Connect(m_address);

            m_schedulerThread = new ThreadLocal <bool>(() => false);

            if (m_ownPoller)
            {
                m_poller.PollTillCancelledNonBlocking();
            }
        }
Ejemplo n.º 10
0
 private static void SendDumperMessage(NetMQContext mqContext, string fileName, long id)
 {
     try
     {
         var dumperAddress = ConfigurationManager.AppSettings["DumperAddress"];
         if (!string.IsNullOrEmpty(dumperAddress))
         {
             using (var sender = mqContext.CreatePushSocket())
             {
                 sender.Connect(dumperAddress);
                 sender.Send("source "+fileName+" "+id);
             }
         }
     }
     catch(Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
     }
 }
Ejemplo n.º 11
0
 public NetMQScheduler([NotNull] NetMQContext context, [CanBeNull] Poller poller = null) :
     this(poller, context.CreatePushSocket(), context.CreatePullSocket())
 {
 }
Ejemplo n.º 12
0
 public NetMQScheduler(NetMQContext context, Poller poller = null) :
     this(poller, context.CreatePushSocket(), context.CreatePullSocket())
 {
 }
Ejemplo n.º 13
0
 public NetMQScheduler( NetMQContext context,  Poller poller = null) : 
     this(poller, context.CreatePushSocket(), context.CreatePullSocket())
 {
     
 }