void _cedaSubscribe_OnCedaMessage(com.adaptiveMQ2.message.Message msg) { CedaObject co = CedaObject.ToCedaObject(msg); string str = string.Format("receive a msg,topic={0},MessageBody=\n{1}", co.Topic, co.MessageBody); logHelper.Info(str); }
void _cedaSubscribe_OnCedaMessage(com.adaptiveMQ2.message.Message msg) { TopicCount++; OneSCount++; //StopTime = DateTime.Now; //TimeSpan ts = StopTime - StartTime; //int hourTime = ts.Hours; //int minuteTime = ts.Minutes; //int secondTime = (hourTime * 3600) + (minuteTime * 60) + ts.Seconds; //labelTime.Text = secondTime.ToString() + "S"; labelCount.Text = TopicCount.ToString(); int clear = -1; if (!int.TryParse(txtClear.Text, out clear)) { clear = int.MaxValue; } if (ClearCount >= clear) { if (ClearCount > 0) { SetMsg(null); ClearCount = 0; } } else { ClearCount++; CedaObject co = CedaObject.ToCedaObject(msg); string str = string.Format("receive a msg,topic={0},MessageBody=\n{1}", co.Topic, co.MessageBody); logHelper.Info(str); } }
private void ConnectionServer() { _cedaSubscribe = new CedaManager(logHelper); _cedaSubscribe.OnCedaMessage += new Action <com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage); string host = txtHost.Text.Trim(); int port = 0; if (!Int32.TryParse(txtPort.Text.Trim(), out port)) { logHelper.Warn("port is error!"); return; } _clientInfo = new ClientInfo(); if ("ACS".Equals(cbType.Text.Trim())) { if (!host.EndsWith(".httpMQTunnel")) { host = string.Format("{0}/mq.httpMQTunnel", host); } _clientInfo.setAddress(host, port); if (ckSSL.Checked) { _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTPS; } else { _clientInfo.Protocol = ClientInfo.PROTOCOL_HTTP; } if (cbVS.Checked) { _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType); } } else if ("CEDA".Equals(cbType.Text.Trim())) { _clientInfo.setAddress(host, port); _clientInfo.setUser("test", "test"); if (ckSSL.Checked) { _clientInfo.Protocol = ClientInfo.PROTOCOL_TCPS; } else { _clientInfo.Protocol = ClientInfo.PROTOCOL_TCP; } if (cbVS.Checked) { _clientInfo.LoginMessage = CedaObject.GetLoginMessage(txtUserName.Text, txtPwd.Text, txtRole.Text, null, encryption, clientType); } } string temp = string.Format("Address:{0}:{1},Topic:{2}", _clientInfo.AddressHost, _clientInfo.AddressPort, txtTopic.Text); logHelper.Info(temp); request = new Message(); request.Destination = new Destination(txtTopic.Text.Trim()); request.SvrID = cbServiceName.Text; request.MessageBody.addString((short)3, txtRequest.Text.Trim()); request.MessageBody.addString((short)4, "JSON"); request.MessageBody.addInt((short)5, 0); request.MessageBody.addString(7, DateTime.Now.ToString("yyyyMMdd HH:mm:ss")); ThreadPool.QueueUserWorkItem(o => { _cedaSubscribe.Connect(_clientInfo); //if (false) //{ // if (_cedaSubscribe != null) // { // _cedaSubscribe.Disconnect(); // _cedaSubscribe.OnCedaMessage -= new Action<com.adaptiveMQ2.message.Message>(_cedaSubscribe_OnCedaMessage); // _cedaSubscribe = null; // } //} if (_cedaSubscribe != null && _cedaSubscribe.IsConnected) { _cedaSubscribe.isStopRequest = false; while (_cedaSubscribe != null && !_cedaSubscribe.isStopRequest) { if (_cedaSubscribe.IsConnected) { Message reply = _cedaSubscribe.Request(request); CedaObject co = CedaObject.ToCedaObject(reply); if (co != null) { logHelper.Info(co.Topic + ":" + co.MessageBody); } else { logHelper.Error("reply is null"); } } Thread.Sleep(1000); } } }); SetButtonEnable("0111"); }