示例#1
0
        /// <summary>
        /// 初始化
        /// </summary>
        public ActiveMQHelper(IActiveMQMsgHandler msgHandler = null, bool isNeedPwd = false)
        {
            try
            {
                if (msgHandler == null)
                {
                    msgHandler = new DefaultActiveMQMsgHandler();
                }
                _msgHandler = msgHandler;

                //初始化工厂
                _factory = new ConnectionFactory(ActiveMQConfig.CONNECTION_INFO);

                //通过工厂建立连接
                if (!isNeedPwd)
                {
                    _connection = _factory.CreateConnection();
                }
                else
                {
                    _connection = _factory.CreateConnection(ActiveMQConfig.MQ_ACCOUNT, ActiveMQConfig.MQ_PWD);
                }

                _connection.ClientId = ActiveMQConfig.CLIENT_ID;
                _connection.Start();
                //通过连接创建Session会话
                _session = _connection.CreateSession();
            }
            catch (Exception e)
            {
                //引发事件
                _eventSource.RaiseErroeMsgEvent(this.BusinessName, e.Message);
            }
        }
示例#2
0
 public ActiveMQMsgEventListener(IActiveMQMsgHandler msgHandler)
 {
     _msgHandler = msgHandler;
 }