private void ConnectionServer() { _cedaSubscribe.OnCedaMessage += new Action <com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage); _clientInfo = new ClientInfo(); _clientInfo.setAddress(ip, port); _clientInfo.setUser("monitor", "monitor"); _clientInfo.Protocol = ClientInfo.PROTOCOL_TCP; ThreadPool.QueueUserWorkItem(o => { _cedaSubscribe.Connect(_clientInfo); if (_cedaSubscribe == null) { return; } if (_cedaSubscribe.IsConnected) { msd = getMSD(); craeteNodeLine(); _cedaSubscribe.SubscribeWithImage("YM.M.SI.*", svrId); _cedaSubscribe.Subscribe("YM.M.W.*"); } }); }
//建立连接 public void connect() { initialize_ip_port_svrID(); ClientInfo clientInfo = new ClientInfo(); clientInfo.setAddress(ip, port); clientInfo.setUser("monitor", "monitor"); clientInfo.Protocol = ClientInfo.PROTOCOL_TCP; ThreadPool.QueueUserWorkItem(o => { cedaManager.Connect(clientInfo); if (cedaManager == null) { return; } if (cedaManager.IsConnected) { //string msgbody = MsgHelper.Serializer<Dictionary<string, object>>(dic); cedaManager.SubscribeWithImage(topicStr, svrId); List <String> topicList = new List <String>(); topicList.Add(topicStr); cedaManager.Subscribe(topicStr); while (cedaManager.IsConnected) { if (cedaManager.IsConnected) { Message reply = cedaManager.Request(getMessage()); CedaObject co = CedaObject.ToCedaObject(reply); if (co != null) { LogHelper.Debug(co.Topic + ":" + co.MessageBody); HisMonitorMessages result = MsgHelper.Deserialize <HisMonitorMessages>(co.MessageBody, MsgSerializerType.Json); lock (pointData) { setLinesData(result.Data); createLines(); } LogHelper.Debug("init end."); break; } else { LogHelper.Error("reply is null."); } } Thread.Sleep(1000); } } }); }
//连接服务器,并订阅目标消息 private void ConnectionServer() { //MessageBox.Show("kaishilianjie"); _cedaSubscribe = new CedaManager(logHelper); _cedaSubscribe.OnCedaMessage += new Action <com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage); _clientInfo = new ClientInfo(); _clientInfo.setAddress(ip, port); _clientInfo.setUser("monitor", "monitor"); _clientInfo.Protocol = ClientInfo.PROTOCOL_TCP; //MessageBox.Show("启动线程,并订阅消息"); try { ThreadPool.QueueUserWorkItem(o => { _cedaSubscribe.Connect(_clientInfo); if (_cedaSubscribe == null) { return; } if (_cedaSubscribe.IsConnected) { string msgbody = MsgHelper.Serializer <Dictionary <string, object> >(dic); request.MessageBody.addString((short)3, msgbody); request.MessageBody.addString((short)4, "JSON"); request.MessageBody.addInt((short)5, 0); request.MessageBody.addString(7, DateTime.Now.ToString("yyyyMMdd HH:mm:ss")); sentMsg(); _cedaSubscribe.Subscribe("monitor.event.*"); } }); } catch { txtMsg.Text = "连接失败,请检查链接。SerID:" + serId + " IP:" + ip + " PORT:" + port; } }
private void subTopic() { if (topicList.Count > 0) { cedaClient.Subscribe(topicList); } LogHelper.Debug("Subscribe topic:" + topicStr); bool result = true; if (topicList.Count == 0) { result = false; disconnect(); //System.Windows.Forms.MessageBox.Show(this, "当前进程没有监控topic", "提示", System.Windows.Forms.MessageBoxButtons.OK); } if (sendResult != null) { sendResult(result); } }
private void ConnectionServer() { _cedaSubscribe = new CedaManager(logHelper); _cedaSubscribe.OnCedaMessage += new Action <com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage); _clientInfo = new ClientInfo(); _clientInfo.setAddress(ip, port); _clientInfo.setUser("monitor", "monitor"); _clientInfo.Protocol = ClientInfo.PROTOCOL_TCP; ThreadPool.QueueUserWorkItem(o => { _cedaSubscribe.Connect(_clientInfo); if (_cedaSubscribe == null) { return; } if (_cedaSubscribe.IsConnected) { _cedaSubscribe.Subscribe("YM.MONITOR"); } }); }