Beispiel #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();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            ConnectionConfig connCfg = new ConnectionConfig();

            connCfg.Host = "127.0.0.1";
            connCfg.Port = 15555;
            Connection conn = new Connection(connCfg);

            WorkerConfig workerCfg = new WorkerConfig();

            workerCfg.Service = "MyPubSub";
            workerCfg.Mode    = WorkerConfig.MODE_PUBSUB;

            Worker worker = new Worker(conn, workerCfg);

            worker.Subscribe("topic1");

            Console.WriteLine("C# Subscriber on {0}", "topic1");
            while (true)
            {
                try
                {
                    ZMsg msg = worker.Recv();
                    msg.Dump();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    break;
                }
            }
            conn.Destroy();
            worker.Destroy();
        }
Beispiel #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();
        }
Beispiel #4
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();
        }
Beispiel #5
0
        public ZMsg HandleRequest(ZMsg request)
        {
            request.Dump();

            ZMsg result = new ZMsg();

            result.PushBack("this is from pooled c# worker");

            return(result);
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            //1) 创建连接到ZBUS总线
            ConnectionConfig connCfg = new ConnectionConfig();

            connCfg.Host = "127.0.0.1";
            connCfg.Port = 15555;
            Connection conn = new Connection(connCfg);

            //2) 注册服务(MyService)
            WorkerConfig workerCfg = new WorkerConfig();

            workerCfg.Service = "MyService";
            workerCfg.Mode    = WorkerConfig.MODE_LB;//负载均衡模式
            Worker worker = new Worker(conn, workerCfg);

            Console.WriteLine("C# Simple Worker Running...");
            //3) 服务业务逻辑循环体(等待ZBUS总线分发请求,处理请求,返回请求结果)
            while (true)
            {
                try
                {
                    //3.1) 等待ZBUS总线分发请求消息
                    ZMsg msg = worker.Recv();

                    //3.2) 业务逻辑处理请求消息
                    msg.Dump();

                    //3.3) 返回处理后的消息
                    msg = new ZMsg();
                    msg.PushBack("this is from c# loadbalancer");
                    worker.Send(msg);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    break;
                }
            }

            //4) 清除连接相关
            conn.Destroy();
            worker.Destroy();
        }