Пример #1
0
        /// <summary>
        /// 通过RabbitMQ向外发送消息
        /// </summary>
        /// <param name="desc">业务描述</param>
        /// <param name="entity">数据实体</param>
        /// <param name="messageId">消息id(guid)</param>
        /// <param name="parkingCode">停车场编码</param>
        public bool SendMessageForRabbitMQ(string desc, string entity, string messageId, string parkingCode, string routingKey = "", string exchange = "")
        {
            bool flag = false;

            try
            {
                if (string.IsNullOrEmpty(routingKey))
                {
                    routingKey = parkingCode;
                }

                if (string.IsNullOrEmpty(exchange))
                {
                    exchange = parkingCode + "_CameraExchange";
                }

                //if (string.IsNullOrWhiteSpace(parkingCode))
                //{
                //    m_logger.LogInfo(LoggerLogicEnum.Communication, "", parkingCode, "", "Fujica.com.cn.Communication.RabbitMQ.RabbitMQSender.SendMessageForRabbitMQ", "RabbitMQ对象缺少通道或路由键");
                //    return flag;
                //}

                RabbitMQProduserMsgType msgType;
                if (exchange == "FuJiCaYunCameraParkInit.fanout")
                {
                    msgType = RabbitMQProduserMsgType.YunParkDataInitCameraType_fanout;
                }
                else if (exchange == "FuJiCaDynamicAddNewCityCode.direct")
                {
                    exchange = ConfigurationManager.AppSettings["MQManufacturerCode"] + exchange;
                    msgType  = RabbitMQProduserMsgType.Other01Type_direct;
                }
                else
                {
                    msgType = RabbitMQProduserMsgType.YunParkDataType_fanout;
                }

                //创建发送的消息体
                PackongVehicleEntryMQ model = new PackongVehicleEntryMQ()
                {
                    json         = entity,
                    rabbitMQType = msgType,
                    idMsg        = messageId,
                    routingKey   = routingKey,
                    exchange     = exchange,
                    parkingCode  = parkingCode
                };
                string jsonMsg = m_serializer.Serialize(model);
                //m_logger.LogInfo(LoggerLogicEnum.Communication, "", parkingCode, "", "Fujica.com.cn.Communication.RabbitMQ.RabbitMQSender.SendMessageForRabbitMQ", "序列化结果" + jsonMsg);
                Startup.AsyncInitSendMQMsgOfYunParkData(jsonMsg);
                m_logger.LogInfo(LoggerLogicEnum.Communication, "", parkingCode, "", "Fujica.com.cn.Communication.RabbitMQ.RabbitMQSender.SendMessageForRabbitMQ", string.Format("MQ下发成功!下发业务:{0};发送参数:{1};", desc, jsonMsg));
                flag = true;
            }
            catch (Exception ex)
            {
                m_logger.LogError(LoggerLogicEnum.Communication, "", parkingCode, "", "Fujica.com.cn.Communication.RabbitMQ.RabbitMQSender.SendMessageForRabbitMQ", "RabbitMQ对象创建失败OR通过RabbitMQ发送消息失败", ex.ToString());
            }
            return(flag);
        }