Exemplo n.º 1
0
        /// <summary>
        /// 构造方法
        /// 初始化各个对象以便就绪
        /// 只初始化交换机与基本属性,队列定义请重写Init方法进行操作
        /// </summary>
        /// <param name="channel">渠道</param>
        /// <param name="amqpQueue">AMQP队列信息</param>
        /// <param name="isDeclare">是否定义</param>
        /// <param name="log">日志</param>
        public RabbitCoreBase(IModel channel, AmqpQueueInfo amqpQueue, bool isDeclare, ILogable log = null)
        {
            ValidateUtil.ValidateNull(channel, "渠道");
            ValidateUtil.ValidateNull(amqpQueue, "AMQP队列信息");

            this.channel   = channel;
            this.amqpQueue = amqpQueue;

            if (log == null)
            {
                this.log = LogTool.DefaultLog;
            }
            else
            {
                this.log = log;
            }

            if (isDeclare)
            {
                channel.ExchangeDeclare(amqpQueue.ExchangeName, amqpQueue.Type, amqpQueue.Persistent);
                if (amqpQueue.Queue.Qos != null)
                {
                    channel.BasicQos(0, amqpQueue.Queue.Qos.GetValueOrDefault(), false);
                }
            }

            basicProperties            = channel.CreateBasicProperties();
            basicProperties.Persistent = amqpQueue.Persistent;

            Init();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="amqpQueue">AMQP队列信息</param>
        /// <param name="log">日志</param>
        public RabbitExceptionHandle(AmqpQueueInfo amqpQueue, ILogable log = null)
        {
            if (amqpQueue == null)
            {
                throw new ArgumentNullException("AMQP队列信息不能为null");
            }
            this.amqpQueue = amqpQueue;

            if (log == null)
            {
                log = LogTool.DefaultLog;
            }
            else
            {
                this.log = log;
            }

            InitExceptionHandle();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 生成业务异常信息
        /// </summary>
        /// <param name="ex">异常</param>
        /// <param name="queueMessage">队列消息</param>
        /// <param name="amqpQueue">AMQP队列信息</param>
        /// <param name="log">日志</param>
        /// <param name="desc">描述</param>
        /// <returns>业务异常信息</returns>
        public static BusinessExceptionInfo BuilderBusinessException(Exception ex, object queueMessage, AmqpQueueInfo amqpQueue, ILogable log, string desc = null)
        {
            if (log == null)
            {
                throw new ArgumentNullException("日志不能为null");
            }
            string queueMessageJson = null;

            if (queueMessage != null)
            {
                try
                {
                    queueMessageJson = JsonUtil.SerializeIgnoreNull(queueMessage);
                }
                catch (Exception ex1)
                {
                    log.ErrorAsync("JSON序列化业务异常信息出错", ex1, typeof(AmqpUtil).Name);

                    return(null);
                }
            }

            var busEx = new BusinessExceptionInfo()
            {
                Time                   = DateTime.Now,
                ServiceName            = string.IsNullOrWhiteSpace(amqpQueue.ExceptionHandle.ServiceName) ? UtilTool.AppServiceName : amqpQueue.ExceptionHandle.ServiceName,
                ExceptionString        = ex.ToString(),
                ExceptionMessage       = ex.Message,
                Exchange               = amqpQueue.ExchangeName,
                Queue                  = amqpQueue.Queue.Name,
                QueueMessageJsonString = queueMessageJson,
                Desc                   = desc,
                ServerMachineName      = Environment.MachineName,
                ServerIP               = NetworkUtil.LocalIP
            };

            return(busEx);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 构造方法
 /// 初始化各个对象以便就绪
 /// 只初始化交换机与基本属性,队列定义请重写Init方法进行操作
 /// </summary>
 /// <param name="channel">渠道</param>
 /// <param name="amqpQueue">AMQP队列信息</param>
 /// <param name="log">日志</param>
 /// <param name="exceptionHandle">异常处理</param>
 public RabbitConsumer(IModel channel, AmqpQueueInfo amqpQueue, ILogable log = null, IExceptionHandle exceptionHandle = null)
     : base(channel, amqpQueue, true, log)
 {
     this.exceptionHandle = exceptionHandle;
 }
Exemplo n.º 5
0
 /// <summary>
 /// 构造方法
 /// 初始化各个对象以便就绪
 /// 只初始化交换机与基本属性,队列定义请重写Init方法进行操作
 /// </summary>
 /// <param name="channel">渠道</param>
 /// <param name="amqpQueue">AMQP队列信息</param>
 /// <param name="log">日志</param>
 public RabbitProducer(IModel channel, AmqpQueueInfo amqpQueue, ILogable log = null)
     : base(channel, amqpQueue, false, log)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// 构造方法
 /// 初始化各个对象以便就绪
 /// 只初始化交换机与基本属性,队列定义请重写Init方法进行操作
 /// </summary>
 /// <param name="channel">渠道</param>
 /// <param name="amqpQueue">AMQP队列信息</param>
 /// <param name="log">日志</param>
 public RabbitRpcClient(IModel channel, AmqpQueueInfo amqpQueue, ILogable log = null)
     : base(channel, amqpQueue, false, log)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// 创建Rpc服务端
 /// </summary>
 /// <param name="amqpQueue">AMQP队列</param>
 /// <returns>Rpc服务端</returns>
 protected override IRpcServer CreateRpcServer(AmqpQueueInfo amqpQueue) => new RabbitRpcServer(CreateChannel(), amqpQueue);
Exemplo n.º 8
0
 /// <summary>
 /// 创建Rpc客户端
 /// </summary>
 /// <param name="amqpQueue">AMQP队列</param>
 /// <returns>Rpc客户端</returns>
 protected override IRpcClient CreateRpcClient(AmqpQueueInfo amqpQueue) => new RabbitRpcClient(CreateChannel(), amqpQueue);
Exemplo n.º 9
0
 /// <summary>
 /// 创建消费者
 /// </summary>
 /// <param name="amqpQueue">AMQP队列</param>
 /// <returns>消费者</returns>
 protected override IConsumer CreateConsumer(AmqpQueueInfo amqpQueue) => new RabbitConsumer(CreateChannel(), amqpQueue);
Exemplo n.º 10
0
 /// <summary>
 /// 创建生产者
 /// </summary>
 /// <param name="amqpQueue">AMQP队列</param>
 /// <returns>生产者</returns>
 protected override IProducer CreateProducer(AmqpQueueInfo amqpQueue) => new RabbitProducer(CreateChannel(), amqpQueue);