Context class of the NetMQ, you should have only one context in your application
Inheritance: IDisposable
コード例 #1
1
ファイル: MDPClient.cs プロジェクト: wangkai2014/netmq
 /// <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;
 }
コード例 #2
0
ファイル: XForwarder.cs プロジェクト: yonglehou/Daytona
 /// <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);
 }
コード例 #3
0
ファイル: TcpGateway.cs プロジェクト: heartysoft/res
 public TcpGateway(NetMQContext ctx, string endpoint, MessageProcessor processor)
 {
     _ctx = ctx;
     _endpoint = endpoint;
     _processor = processor;
     _socket = connect();
 }
コード例 #4
0
ファイル: FeedZmQPublisher.cs プロジェクト: Grovesy/Feeds
 public FeedZmQPublisher(string address, ILog log)
 {
     _log = log;
     _context = NetMQContext.Create();
     _socket = _context.CreatePushSocket();
     _socket.Bind(address);
 }
コード例 #5
0
ファイル: SharpDBClient.cs プロジェクト: JackWangCUMT/SharpDB
        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;
                }
            }
        }
コード例 #6
0
ファイル: SharpDBClient.cs プロジェクト: JackWangCUMT/SharpDB
 public SharpDBClient(string connectionString)
 {
     m_context = NetMQContext.Create();
     m_contextOwned = true;
     ConnectionString = connectionString;
     SerializerFactory = () => new BsonSerializer();
 }
コード例 #7
0
ファイル: NetMQWorker.cs プロジェクト: buldo/MQExperiments
 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);
 }
コード例 #8
0
ファイル: SharpDBClient.cs プロジェクト: JackWangCUMT/SharpDB
 public SharpDBClient(NetMQContext context, string connectionString)
 {
     m_context = context;
     m_contextOwned = false;
     ConnectionString = connectionString;
     SerializerFactory = () => new BsonSerializer();
 }
コード例 #9
0
ファイル: FanBrocker.cs プロジェクト: buldo/MQExperiments
        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");
                }

            });
        }
コード例 #10
0
ファイル: NetMQSenderManager.cs プロジェクト: yonglehou/Smoke
        /// <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));
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
ファイル: Control.cs プロジェクト: gwenzek/icsharp
        public Control(int port, NetMQContext context)
        {
            this.port = port;
            this.context = context;

            this.server = this.context.CreateRouterSocket();
        }
コード例 #13
0
ファイル: Simple.cs プロジェクト: david-x-chen/ReliablePubSub
        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();
              }
        }
コード例 #14
0
 internal NmqMessageSender(Uri serviceUri)
 {
     context = NetMQContext.Create();
     socket = context.CreateRequestSocket();
     var address = string.Format("tcp://{0}:{1}", serviceUri.Host, serviceUri.Port);
     socket.Connect(address);
 }
コード例 #15
0
ファイル: ActorTests.cs プロジェクト: yonglehou/Daytona
       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;
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        public ZmqClient()
        {
            context = NetMQContext.Create();

            subSocket = context.CreateSubscriberSocket();
            subSocket.Options.ReceiveHighWatermark = 1000;
            subSocket.Connect(MarketDataSettings.RealTimeUpdateServerAddress);
        }
コード例 #18
0
ファイル: AsyncWorker.cs プロジェクト: buldo/MQExperiments
 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);
 }
コード例 #19
0
        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);
        }
コード例 #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);
        }
コード例 #21
0
ファイル: GWMQServer.cs プロジェクト: dreign/Famliy.Finance
 public void Init(int port, MQServerType type)
 {
     _type = type;
     _port = port;
     _isStart = true;
     _context = NetMQContext.Create();
     CreateServer();
 }
コード例 #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);
        }
コード例 #23
0
 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);
 }
コード例 #24
0
        public ZmqService()
        {
            primitiveQuoteService = new YahooFinancialDataService();
            subscribedTickerList = new List<string>();
            subscribedTickerList.AddRange(MarketDataSettings.StartupTickers);
            refreshInterval = MarketDataSettings.ServerRefreshMillis;

            socketFactory = NetMQContext.Create();
        }
コード例 #25
0
ファイル: MDPWorker.cs プロジェクト: bbqchickenrobot/netmq
        /// <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;
        }
コード例 #26
0
        /// <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);
        }
コード例 #27
0
        public void Start(int publishPort)
        {
            ctx = NetMQContext.Create();
            publishSocket = ctx.CreatePublisherSocket();

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

            logger.Info("Message publisher started on port " + publishPort);
        }
コード例 #28
0
ファイル: Heartbeat.cs プロジェクト: gwenzek/icsharp
        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();
        }
コード例 #29
0
 private void InitZmq()
 {
     if (_ctx == null)
     {
         _ctx = NetMQContext.Create();
         _socket = _ctx.CreatePublisherSocket();
         var address = string.Format("{0}:{1}", _host, _port);
         _socket.Bind(address);
     }
 }
コード例 #30
0
ファイル: ZrePeer.cs プロジェクト: torshy/DotNetZyre
 public ZrePeer(NetMQContext context, Guid identity)
 {
     _context = context;
     _identity = identity;
     _headers = new ConcurrentDictionary<string, string>();
     _sentSequence = 0;
     _wantSequence = 0;
     _evasiveAt = 0;
     _expiredAt = 0;
 }
コード例 #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();
            }
        }
コード例 #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)));
 }
コード例 #33
0
ファイル: NetMQActor.cs プロジェクト: xuzhe35/netmq
 public static NetMQActor Create(NetMQContext context, IShimHandler shimHandler)
 {
     return(new NetMQActor(context, shimHandler));
 }
コード例 #34
0
ファイル: NetMQScheduler.cs プロジェクト: newstrading/netmq
 public NetMQScheduler(NetMQContext context, Poller poller = null) :
     this(poller, context.CreatePushSocket(), context.CreatePullSocket())
 {
 }
コード例 #35
0
 public static NetMQActor Create([NotNull] NetMQContext context, [NotNull] IShimHandler shimHandler)
 {
     return(new NetMQActor(context, shimHandler));
 }
コード例 #36
0
 public static NetMQActor Create([NotNull] NetMQContext context, [NotNull] ShimAction action)
 {
     return(new NetMQActor(context, new ActionShimHandler(action)));
 }
コード例 #37
0
 public NetMQScheduler([NotNull] NetMQContext context, [CanBeNull] Poller poller = null) :
     this(poller, context.CreatePushSocket(), context.CreatePullSocket())
 {
 }
コード例 #38
0
ファイル: NetMQActor.cs プロジェクト: newstrading/netmq
 public static NetMQActor Create(NetMQContext context, ShimAction action)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), new ActionShimHandler(action)));
 }
コード例 #39
0
ファイル: NetMQActor.cs プロジェクト: newstrading/netmq
 public static NetMQActor Create <T>(NetMQContext context, ShimAction <T> action, T state)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), new ActionShimHandler <T>(action, state)));
 }
コード例 #40
0
ファイル: NetMQActor.cs プロジェクト: newstrading/netmq
 public static NetMQActor Create(NetMQContext context, IShimHandler shimHandler)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), shimHandler));
 }