Example #1
0
        /// <summary>
        /// 创建消息生产者
        /// </summary>
        /// <param name="brokerUri">消息队列地址</param>
        /// <param name="type">消息队列类型</param>
        /// <param name="name">消息队列名称</param>
        /// <param name="onException">异常处理</param>
        public SimpleProducer(string brokerUri, MQType type, string name, Action <Exception> onException = null)
        {
            if (string.IsNullOrWhiteSpace(brokerUri))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(brokerUri));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(name));
            }

            _brokerUri   = brokerUri;
            _name        = name;
            _destination = type.CreateDestination(name);
            _onException = onException;
        }
Example #2
0
        /// <summary>
        /// 创建消费者
        /// </summary>
        /// <param name="brokerUri">消息队列地址</param>
        /// <param name="type">消息队列类型</param>
        /// <param name="name">消息队列名称</param>
        /// <param name="messageReceived">接收消息</param>
        /// <param name="onException">异常处理,返回true则会重新消费</param>
        public SimpleConsumer(string brokerUri, MQType type, string name, Action <ITextMessage> messageReceived, Func <Exception, bool> onException = null)
        {
            if (string.IsNullOrWhiteSpace(brokerUri))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(brokerUri));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(name));
            }

            _messageReceived = messageReceived;
            _onException     = onException;

            _connectionFactory = new ConnectionFactory(brokerUri);
            _destination       = type.CreateDestination(name);
        }