Ejemplo n.º 1
0
        void Start()
        {
            PseudoRandom rand = PseudoRandom.getInstance();

            ThreadPool.QueueUserWorkItem((obj) => {
                using (var context = NetMQContext.Create())
                    using (pubSocket = context.CreatePublisherSocket()) {
                        ConsoleEx.DebugLog("Publisher socket binding...", ConsoleEx.RED);

                        pubSocket.Options.SendHighWatermark = 1000;
                        pubSocket.Bind("tcp://*:52323");

                        for (var i = 0; i < 50; i++)
                        {
                            if (quite)
                            {
                                break;
                            }

                            var randomizedTopic = rand.next(1000);
                            if (randomizedTopic > 50)
                            {
                                var msg = "TopicA msg-" + i;
                                ConsoleEx.DebugLog("Sending message : " + msg, ConsoleEx.RED);
                                pubSocket.SendMore("TopicA").Send(msg);
                            }
                            else
                            {
                                var msg = "TopicB msg-" + i;
                                ConsoleEx.DebugLog("Sending message : " + msg, ConsoleEx.RED);
                                pubSocket.SendMore("TopicB").Send(msg);
                            }

                            Thread.Sleep(500);
                        }
                        ConsoleEx.DebugLog("Publisher job is down.", ConsoleEx.RED);
                    }
            });
        }
Ejemplo n.º 2
0
        public void send(IpcMsg msg)
        {
            if (msg != null)
            {
                                #if DEBUG
                if (msg.op != OP.NpcMove)
                {
                    string plain = fastJSON.JSON.Instance.ToJSON(msg);
                    ConsoleEx.DebugLog("Sending message : " + msg.op.ToString() + "  " + plain, ConsoleEx.YELLOW);
                }
                                #endif

                if (isBinded)
                {
                    byte[] outBytes = ProtoLoader.serializeProtoObject <IpcMsg>(msg);
                    pubSocket.SendMore(msg.op.ToString()).Send(outBytes);
                }
            }
        }
            private void OnShimReady(object sender, NetMQSocketEventArgs e)
            {
                string command = e.Socket.ReceiveString();

                switch (command)
                {
                case ActorKnownMessages.END_PIPE:
                    poller.Stop(false);
                    break;

                case PublishTicker:
                    string topic = e.Socket.ReceiveString();
                    string json  = e.Socket.ReceiveString();
                    publisherSocket.
                    SendMore(topic).
                    Send(json);
                    break;
                }
            }