Exemplo n.º 1
0
        private void OnRecvWorker()
        {
            var polling = new Polling(PollingEvents.RecvReady, this._socket);

            polling.RecvReady += socket =>
            {
                var topic          = _socket.RecvString();
                var messageInBytes = _socket.Recv();
                var message        = _deserializer(messageInBytes);

                this.OnReceived(topic, message);
            };

            try
            {
                while (_started)
                {
                    polling.Poll(1000);
                }
            }
            catch (ZmqException e)
            {
                if (LogAdapter.LogEnabled)
                {
                    LogAdapter.LogDebug(this.GetType().FullName, "BaseSubscriber exception. Disposing. Details: " + e.ToString());
                }

                this.Dispose();
            }
        }
Exemplo n.º 2
0
        private void EventsWorker()
        {
            try
            {
                while (!_disposed)
                {
                    var binary = _pairSocket.Recv();

                    if (binary == null || binary.Length == 0)
                    {
                        continue;
                    }

                    var ev  = (MonitorEvents)BitConverter.ToUInt16(binary, 0);
                    int val = 0;

                    if (binary.Length > sizeof(UInt16))
                    {
                        val = BitConverter.ToInt32(binary, sizeof(UInt16));
                    }

                    ZmqError error   = null;
                    var      address = "";

                    switch (ev)
                    {
                    case MonitorEvents.BindFailed:
                    case MonitorEvents.AcceptFailed:
                    case MonitorEvents.CloseFailed:
                        address = _pairSocket.RecvString();
                        error   = new ZmqError(val);
                        break;

                    case MonitorEvents.MonitorStopped:
                        break;

                    default:
                        address = _pairSocket.RecvString();
                        break;
                    }

                    FireEvent(ev, address, error);
                }
            }
            catch (ZmqException ex)
            {
                if (ex.ZmqErrorCode != ZmqErrorCode.ETERM)
                {
                    if (LogAdapter.LogEnabled)
                    {
                        LogAdapter.LogError("Monitor", ex.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                if (LogAdapter.LogEnabled)
                {
                    LogAdapter.LogError("Monitor", e.ToString());
                }
            }
            finally
            {
                this.Dispose();
            }
        }