Esempio n. 1
0
        public static void Main(string[] args)
        {
            //1) 创建连接
            ConnectionConfig config = new ConnectionConfig();

            config.Host = "127.0.0.1";
            config.Port = 15555;
            BusClient client = new BusClient(config);

            //2) 异步控制结构
            AsynCtrl ctrl = new AsynCtrl();

            ctrl.Service   = "MyService";
            ctrl.PeerId    = "local_mq"; //消息投递目标ID,与接收方协商
            ctrl.MessageId = "10000";
            ctrl.Timeout   = 2500;       ////异步投递失败提示最长时间(ms)


            //3) 消息体(帧组成)
            ZMsg msg = new ZMsg();

            msg.PushBack("asyn call frame1");
            msg.PushBack("asyn call frame2");

            //4) 发送异步消息
            msg = client.Send(ctrl, msg);
            msg.Dump();

            //5)销毁链接
            client.Destroy();

            Console.ReadKey();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            //1) 创建连接
            ConnectionConfig config = new ConnectionConfig();

            config.Host = "127.0.0.1";
            config.Port = 15555;
            BusClient client = new BusClient(config);

            //2) 组装消息(消息帧数组)
            ZMsg request = new ZMsg();

            request.PushBack("Frame1");          //消息帧1 -- 字符类型
            request.PushBack(new byte[10]);      //消息帧2 -- 二进制串
            request.PushBack("request from C#"); //消息帧3 -- 字符类型

            //3) 向ZBUS总线发送请求
            ZMsg result = client.Request("MyService", "", request);

            result.Dump();


            //4) 销毁客户端
            client.Destroy();

            Console.ReadKey();
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            //1) 创建连接
            ConnectionConfig connCfg = new ConnectionConfig();

            connCfg.Host = "127.0.0.1";
            connCfg.Port = 15555;
            connCfg.Id   = "local_mq";
            BusClient client = new BusClient(connCfg);

            //2)异步处理消息
            while (true)
            {
                try
                {
                    //recv参数指定发送心跳时间间隔,(防火墙切断链接)
                    ZMsg msg = client.Recv(2500);//2.5s for ping
                    msg.Dump();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    break;
                }
            }

            //3)销毁连接
            client.Destroy();
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            ConnectionConfig config = new ConnectionConfig();

            config.Host = "127.0.0.1";
            config.Port = 15555;
            //config.Verbose = true;

            BusClient client = new BusClient(config);

            ZMsg msg = new ZMsg();

            msg.PushBack("publish from C#");

            bool result = client.Publish("MyPubSub", "", "topic1", msg);

            Console.WriteLine("publish result: " + result);

            client.Destroy();

            Console.ReadKey();
        }