コード例 #1
0
ファイル: AsynSend.cs プロジェクト: firememory/honglm-zbus
        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();
        }
コード例 #2
0
ファイル: AsynRecv.cs プロジェクト: firememory/honglm-zbus
        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();
        }
コード例 #3
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();
        }
コード例 #4
0
 public Rpc(RpcConfig config)
 {
     this.Encoding  = Encoding.UTF8;
     this.Service   = config.Service;
     this.Token     = config.Token;
     this.client    = new BusClient(config);
     this.ownClient = true;
 }
コード例 #5
0
 public Rpc(BusClient client, string service, string token, Encoding encoding, int timeout)
 {
     this.client    = client;
     this.ownClient = false;
     this.Service   = service;
     this.Token     = token;
     this.Encoding  = encoding;
     this.timeout   = timeout;
 }
コード例 #6
0
ファイル: Publisher.cs プロジェクト: firememory/honglm-zbus
        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();
        }