Esempio n. 1
0
        /// <summary>
        /// 添加待处理的消息
        /// </summary>
        /// <param name="item"></param>
        public static void Add(RMqSendMessage item)
        {
            if (item == null)
            {
                return;
            }

            BlockingQueue.Add(item, abandonAction: AbandonMessageHandler);
        }
Esempio n. 2
0
        /// <summary>
        /// 单个消息处理
        /// </summary>
        /// <param name="message"></param>
        private static void SingleDataHandler(RMqSendMessage message)
        {
            if (LongRunRabbitProducer.IsAlive())
            {
                bool result = LongRunRabbitProducer.SendMessage(message, ex =>
                {
                    NLogHelper.Error($"id={message.Id}的消息处理失败:{ex}");
                });

                if (result)
                {
                }
                else
                {
                }
            }
            else
            {
                NLogHelper.Error($"mq连接异常,消息id={message.Id}的消息发送失败");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="exceptionHandler"></param>
        /// <returns></returns>
        public static bool SendMessage(RMqSendMessage msg, Action <Exception> exceptionHandler = null)
        {
            try
            {
                using (IModel channel = _connection.CreateModel())
                {
                    var properties = channel.CreateBasicProperties();
                    //持久
                    properties.DeliveryMode = 2;
                    //超时时间,单位毫秒
                    properties.Expiration = "7200000";
                    channel.BasicPublish(exchange: msg.ExchangeName, routingKey: msg.RoutingKey, basicProperties: properties, body: msg.ContentBytes);
                }


                return(true);
            }
            catch (Exception e)
            {
                exceptionHandler?.Invoke(e);
                return(false);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 消息丢弃
 /// </summary>
 /// <param name="obj"></param>
 private static void AbandonMessageHandler(RMqSendMessage obj)
 {
     NLogHelper.Warn($"存在消息丢弃,消息id={obj.Id}");
 }