Example #1
0
        /// <summary>
        /// 生产者发送消息到队列中
        /// </summary>
        /// <param name="message"></param>
        private void SendMsg(MqMessageModel <T> message)
        {
            try
            {
                var result = _amq.SendMsg(message);
                if (!result)
                {
                    var log = JsonConvert.SerializeObject(new
                    {
                        ActiveMqProvider.ConnectionUrl,
                        MqMessage = message,
                        Message   = "与服务器连接已断开或者尚未连接成功,数据将发送到Redis灾备"
                    });
                    Debug.WriteLine(log);

                    //灾备到redis
                    //MqProvider.EnqueuRedis(_queueTopicType, message, _amq.TimeToLive);
                }
            }
            catch (Exception ex)
            {
                var log = JsonConvert.SerializeObject(new
                {
                    ActiveMqProvider.ConnectionUrl,
                    MqMessage = message,
                    Exception = ex
                });
                Debug.WriteLine(log);

                Debug.WriteLine(ex);
                var eType = ex.GetType();
                if (eType == typeof(RequestTimedOutException) ||
                    eType == typeof(ConnectionClosedException) ||
                    eType == typeof(BrokerException) ||
                    eType == typeof(NMSConnectionException))
                {
                    //灾备到redis
                    //MqProvider.EnqueuRedis(_queueTopicType, message, _amq.TimeToLive);
                }
                else
                {
                    throw ex;
                }
            }
        }
Example #2
0
 /// <summary>
 /// 发送消息到队列
 /// </summary>
 /// <param name="message">mq消息实体</param>
 public void Send(MqMessageModel <T> message)
 {
     SendMsg(message);
 }