Context class of the NetMQ, you should have only one context in your application
Inheritance: IDisposable
Example #1
1
 /// <summary>
 ///     setup the client with standard values
 ///     verbose == false
 ///     timeout == 2500
 ///     reties  == 3
 /// </summary>
 private MDPClient()
 {
     m_ctx = NetMQContext.Create ();
     m_client = null;
     Timeout = TimeSpan.FromMilliseconds (2500);
     Retries = 3;
     m_connected = false;
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XForwarder"/> class.
 /// </summary>
 /// <param name="context">The <see cref="NetMQContext"/> to use when creating the sockets.</param>
 /// <param name="poller">The <see cref="Poller"/> 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 XForwarder(NetMQContext context, Poller poller, string frontendBindAddress, string backendBindAddress,
                   DeviceMode mode = DeviceMode.Threaded)
     : base(poller, context.CreateXSubscriberSocket(), context.CreateXPublisherSocket(), mode)
 {
     this.FrontendSetup.Bind(frontendBindAddress);
     this.BackendSetup.Bind(backendBindAddress);
 }
Example #3
0
 public TcpGateway(NetMQContext ctx, string endpoint, MessageProcessor processor)
 {
     _ctx = ctx;
     _endpoint = endpoint;
     _processor = processor;
     _socket = connect();
 }
Example #4
0
 public FeedZmQPublisher(string address, ILog log)
 {
     _log = log;
     _context = NetMQContext.Create();
     _socket = _context.CreatePushSocket();
     _socket.Bind(address);
 }
Example #5
0
        public void Dispose()
        {
            lock (this)
            {
                if (!m_isDisposed)
                {
                    SharpDBConnection connection;

                    while (m_connections.TryTake(out connection))
                    {
                        connection.Dispose();
                    }

                    if (m_contextOwned)
                    {
                        m_context.Dispose();
                    }

                    m_connections = null;
                    m_context = null;

                    m_isDisposed = true;
                }
            }
        }
Example #6
0
 public SharpDBClient(string connectionString)
 {
     m_context = NetMQContext.Create();
     m_contextOwned = true;
     ConnectionString = connectionString;
     SerializerFactory = () => new BsonSerializer();
 }
Example #7
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);
 }
Example #8
0
 public SharpDBClient(NetMQContext context, string connectionString)
 {
     m_context = context;
     m_contextOwned = false;
     ConnectionString = connectionString;
     SerializerFactory = () => new BsonSerializer();
 }
Example #9
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");
                }

            });
        }
Example #10
0
        /// <summary>
        /// Initializes an instance of a NetMQSenderManager constructing a NetMQSender from the specified NetMQContext and
        /// connects it to the specified address
        /// </summary>
        /// <param name="context"></param>
        public NetMQSenderManager(NetMQContext context, String address)
        {
            var sender = new NetMQSender(context.CreateDealerSocket(), new BinarySerializer(), address);
            sender.Connect();

            Route<object>(new NetMQSenderFactory(address, context));
        }
        /// <summary>
        /// Create reliable client
        /// </summary>
        /// <param name="context"></param>
        /// <param name="addresses">addresses of the reliable servers</param>
        public ReliableClient(NetMQContext context, params string[] addresses)
        {
            m_context = context;
            m_addresses = addresses;

            m_actor = NetMQActor.Create(context, Run);
        }
Example #12
0
        public Control(int port, NetMQContext context)
        {
            this.port = port;
            this.context = context;

            this.server = this.context.CreateRouterSocket();
        }
Example #13
0
        public void Run(params string[] addresses)
        {
            using (m_context = NetMQContext.Create())
              {
            var subscriber = Connect(addresses);

            if (subscriber == null)
              throw new Exception("cannot connect to eny of the endpoints");

            // timeout timer, when heartbeat was not arrived for 5 seconds
            m_timeoutTimer = new NetMQTimer(TimeSpan.FromSeconds(5));
            m_timeoutTimer.Elapsed += (sender, args) =>
            {
              // timeout happend, first dispose existing subscriber
              subscriber.Dispose();
              m_poller.RemoveSocket(subscriber);

              // connect again
              subscriber = Connect(addresses);

              if (subscriber == null)
            throw new Exception("cannot connect to eny of the endpoints");

              m_poller.AddSocket(subscriber);
            };

            m_poller = new Poller(subscriber);
            m_poller.AddTimer(m_timeoutTimer);

            m_poller.PollTillCancelled();
              }
        }
 internal NmqMessageSender(Uri serviceUri)
 {
     context = NetMQContext.Create();
     socket = context.CreateRequestSocket();
     var address = string.Format("tcp://{0}:{1}", serviceUri.Host, serviceUri.Port);
     socket.Connect(address);
 }
Example #15
0
       private Task RunSubscriber(NetMQContext context)
       {
            using (NetMQSocket syncClient = context.CreateRequestSocket())
            {
                syncClient.Connect(Pipe.PubSubControlBackAddressClient);
                syncClient.Send(string.Empty);
                syncClient.Receive();
                
                var actions = new Dictionary<string, Delegate>();
                actions.Add("MethodInfo", TestActors);
                actions.Add("ShutDownAllActors", ShutDownAllActors);

                using (var actor = new Actor<Order>(context, new BinarySerializer()))
                {
                    actor.RegisterActor(
                        "Display",
                        string.Empty,
                        "outRoute",
                        null,
                        new BinarySerializer(),
                        new DefaultSerializer(Exchange.ControlChannelEncoding),
                        actions);

                    actor.StartAllActors();
                }               
            }    

            return null;
        }
        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);
        }
        public ZmqClient()
        {
            context = NetMQContext.Create();

            subSocket = context.CreateSubscriberSocket();
            subSocket.Options.ReceiveHighWatermark = 1000;
            subSocket.Connect(MarketDataSettings.RealTimeUpdateServerAddress);
        }
Example #18
0
 public AsyncWorker(int id, NetMQContext context, string address) : base(id)
 {
     _responseSocket = context.CreateResponseSocket();
     _responseSocket.Options.ReceiveHighWatermark = 2;
     _responseSocket.Options.SendHighWatermark = 2;
     _responseSocket.Options.Identity = BitConverter.GetBytes(id);
     _responseSocket.Connect(address);
 }
        public ReliableServer(NetMQContext context, string address)
        {
            m_context = context;
            m_address = address;

            // actor is like thread with builtin pair sockets connect the user thread with the actor thread
            m_actor = NetMQActor.Create(context, Run);
        }
Example #20
0
        /// <summary>
        /// Initializes an instance of a NetMQReceiverManager, constructs a NetMQReceiver from the specified NetMQContext and binds
        /// it to the specified address
        /// </summary>
        /// <param name="context">NetMQContext</param>
        /// <param name="address">Address to connect the NetMQReceiver to</param>
        public NetMQReceiverManager(NetMQContext context, string address)
        {
            if (context == null)
                throw new ArgumentNullException("NetMQContext");

            receiver = new NetMQReceiver(context.CreateRouterSocket(), new BinarySerializer());
			receiver.Bind(address);
        }
Example #21
0
 public void Init(int port, MQServerType type)
 {
     _type = type;
     _port = port;
     _isStart = true;
     _context = NetMQContext.Create();
     CreateServer();
 }
Example #22
0
        public LeaderElection(IList<Peer> peers, object lockObject, NetMQContext context, ILogger logger)
        {
            this.peers = peers;
            this.lockObject = lockObject;
            this.context = context;
            this.logger = logger;

            localPeer = this.peers.First(c => c.IsLocal);
        }
 public SingleThreadedZeroMqGateway(string endpoint, TimeSpan reaperInterval)
 {
     Log.DebugFormat("[STZMG] Starting. Thread Id: {0}", Thread.CurrentThread.ManagedThreadId);
     _ctx = NetMQContext.Create();
     _endpoint = endpoint;
     _reaperInterval = reaperInterval;
     _socket = connect();
     _reapTime = DateTime.Now.Add(reaperInterval);
 }
        public ZmqService()
        {
            primitiveQuoteService = new YahooFinancialDataService();
            subscribedTickerList = new List<string>();
            subscribedTickerList.AddRange(MarketDataSettings.StartupTickers);
            refreshInterval = MarketDataSettings.ServerRefreshMillis;

            socketFactory = NetMQContext.Create();
        }
Example #25
0
        /// <summary>
        ///     create worker with standard parameter
        ///     HeartbeatDelay == 2500 milliseconds
        ///     ReconnectDelay == 2500 milliseconds
        ///     ConnectionRetries == 3
        ///     Verbose == false
        /// </summary>
        private MDPWorker()
        {
            m_ctx = NetMQContext.Create();

            HeartbeatDelay = TimeSpan.FromMilliseconds(2500);
            ReconnectDelay = TimeSpan.FromMilliseconds(2500);
            m_exit = false;
            m_connected = false;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NmqMessageServer"/> class.
        /// </summary>
        /// <param name="messageReceiver">The message receiver.</param>
        /// <param name="port">The port.</param>
        internal NmqMessageServer(IMessageReceiver messageReceiver, int port)
        {
            tokenSource = new CancellationTokenSource();

            this.port = port;
            this.messageReceiver = messageReceiver;
            context = NetMQContext.Create();
            responseQueue = new NmqResponseQueue(context, port);
        }
        public void Start(int publishPort)
        {
            ctx = NetMQContext.Create();
            publishSocket = ctx.CreatePublisherSocket();

            publishSocket.Bind("tcp://*:" + publishPort);

            logger.Info("Message publisher started on port " + publishPort);
        }
Example #28
0
        public Heartbeat(ILog logger,  string address, NetMQContext context)
        {
            this.logger = logger;
            this.address = address;
            this.context = context;

            this.server = context.CreateResponseSocket();
            this.stopEvent = new ManualResetEventSlim();
        }
 private void InitZmq()
 {
     if (_ctx == null)
     {
         _ctx = NetMQContext.Create();
         _socket = _ctx.CreatePublisherSocket();
         var address = string.Format("{0}:{1}", _host, _port);
         _socket.Bind(address);
     }
 }
Example #30
0
 public ZrePeer(NetMQContext context, Guid identity)
 {
     _context = context;
     _identity = identity;
     _headers = new ConcurrentDictionary<string, string>();
     _sentSequence = 0;
     _wantSequence = 0;
     _evasiveAt = 0;
     _expiredAt = 0;
 }
Example #31
0
        public NetMQScheduler([NotNull] NetMQContext context, [CanBeNull] Poller poller = null)
        {
            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();

            var schedulerId = Interlocked.Increment(ref s_schedulerCounter);

            var address = string.Format("{0}://scheduler-{1}", Address.InProcProtocol, schedulerId);

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

            m_currentMessageHandler = OnMessageFirstTime;

            m_serverSocket.ReceiveReady += m_currentMessageHandler;

            m_poller.AddSocket(m_serverSocket);

            m_clientSocket = context.CreatePushSocket();
            m_clientSocket.Connect(address);

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

            if (m_ownPoller)
            {
                m_poller.PollTillCancelledNonBlocking();
            }
        }
Example #32
0
 public static NetMQActor Create <T>([NotNull] NetMQContext context, [NotNull] ShimAction <T> action, T state)
 {
     return(new NetMQActor(context, new ActionShimHandler <T>(action, state)));
 }
Example #33
0
 public static NetMQActor Create(NetMQContext context, IShimHandler shimHandler)
 {
     return(new NetMQActor(context, shimHandler));
 }
Example #34
0
 public NetMQScheduler(NetMQContext context, Poller poller = null) :
     this(poller, context.CreatePushSocket(), context.CreatePullSocket())
 {
 }
Example #35
0
 public static NetMQActor Create([NotNull] NetMQContext context, [NotNull] IShimHandler shimHandler)
 {
     return(new NetMQActor(context, shimHandler));
 }
Example #36
0
 public static NetMQActor Create([NotNull] NetMQContext context, [NotNull] ShimAction action)
 {
     return(new NetMQActor(context, new ActionShimHandler(action)));
 }
Example #37
0
 public NetMQScheduler([NotNull] NetMQContext context, [CanBeNull] Poller poller = null) :
     this(poller, context.CreatePushSocket(), context.CreatePullSocket())
 {
 }
Example #38
0
 public static NetMQActor Create(NetMQContext context, ShimAction action)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), new ActionShimHandler(action)));
 }
Example #39
0
 public static NetMQActor Create <T>(NetMQContext context, ShimAction <T> action, T state)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), new ActionShimHandler <T>(action, state)));
 }
Example #40
0
 public static NetMQActor Create(NetMQContext context, IShimHandler shimHandler)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), shimHandler));
 }