コード例 #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
        public ZMsg Send(AsynCtrl ctrl, ZMsg msg)
        {
            IntPtr c_msg            = C.zmsg_new();
            IEnumerator <byte[]> fe = msg.GetEnumerator();

            while (fe.MoveNext())
            {
                IntPtr c_frame = ZMsg.ToZFramePtr(fe.Current);
                C.zmsg_push_back(c_msg, c_frame);
            }

            IntPtr c_ctrl = C.asyn_ctrl_new(ctrl.Service, ctrl.Token, ctrl.Timeout, ctrl.PeerId, ctrl.MessageId);
            IntPtr res    = C.zbuscli_send(this.connection.Handle, c_ctrl, c_msg);

            C.asyn_ctrl_destroy(out c_ctrl);

            if (res == IntPtr.Zero)
            {
                throw new ZBusException("send timeout");
            }

            ZMsg result = null;

            if (res != IntPtr.Zero)
            {
                result = ZMsg.ToZMsg(res);
            }

            return(result);
        }
コード例 #3
0
        public bool Publish(string service, string token, string topic, ZMsg msg, int timeout = 2500)
        {
            AsynCtrl ctrl = new AsynCtrl();

            ctrl.Service = service;
            ctrl.Token   = token;
            ctrl.Timeout = timeout;

            msg.PushFront(topic);

            ZMsg   res    = this.Send(ctrl, msg);
            string status = res.PopFrontStr();

            if (status != null && status.Equals("200"))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }