コード例 #1
0
        //rabbitmq消息测试
        public void rabbitMqTest(HLProtocolSession session, HLProtocolRequestInfo requestInfo)
        {
            var sendMessage = BitConverter.ToString(requestInfo.Body.getMsgBodyBytes()).Replace("-", " ");
            var sendbody    = Encoding.UTF8.GetBytes(sendMessage);

            try
            {
                connMod    = count1 % Int32.Parse(connCount.Text.Trim());
                channelMod = count1 % Int32.Parse(channelCount_tb.Text.Trim());
                if (channelList.ContainsKey(connectionList[connMod]))
                {
                    properties            = channelList[connectionList[connMod]][channelMod].CreateBasicProperties();
                    properties.Persistent = true;
                    channelList[connectionList[connMod]][channelMod].BasicPublish(exchange: "",           //exchange名称
                                                                                  routingKey: QUEUE_NAME, //如果存在exchange,则消息被发送到名为task_queue的客户端
                                                                                  basicProperties: properties,
                                                                                  body: sendbody);        //消息体
                    count1++;
                    //pubMsgCount.Text = "发送到消息队列消息条数:" + count1.ToString();
                }
            }
            catch (RabbitMQ.Client.Exceptions.BrokerUnreachableException ex)
            {
                session.Logger.Error("\r\n" + ex.Message.ToString() + "\r\n");
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: yincen/MyLearning
 /// <summary>
 /// 协议并没有什么太多复杂逻辑,不需要用到命令模式,直接用这种方式就可以了
 /// </summary>
 /// <param name="session"></param>
 /// <param name="requestInfo"></param>
 private static void HLProtocolServer_NewRequestReceived(HLProtocolSession session,
                                                         HLProtocolRequestInfo requestInfo)
 {
     Console.WriteLine();
     Console.WriteLine("数据来源: " + session.RemoteEndPoint);
     Console.WriteLine("接收数据内容:" + requestInfo.Body);
 }
コード例 #3
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        /// notify:使用AppendText向控件写信息将极大影响消息写入rabbitmq的速度,为了保证rabbitmq的写入速率,建议关闭向控件写入信息,用日志记录即可
        void protocolServer_NewRequestReceived(HLProtocolSession session, HLProtocolRequestInfo requestInfo)
        {
            msgCount++;

            if (requestInfo.Body.errorlog != null)
            {
                session.Logger.Error("\r\n消息解析失败,格式错误!IP:" + session.RemoteEndPoint + "发送::\r\n" + requestInfo.Body.all2);
            }

            //答应消息发送
            if (requestInfo.Body.getMsgRespBytes() != null)
            {
                session.Send(requestInfo.Body.getMsgRespBytes(), 0, requestInfo.Body.getMsgRespBytes().Length);
            }
            //只有位置上报信息才往rabbitmq里面扔,过滤掉心跳包
            if (ExplainUtils.msg_id_terminal_location_info_upload == requestInfo.Body.msgHeader.msgId)
            {
                rabbitMqTest(session, requestInfo);
            }
        }