Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrantMQExtend{M}"/> class.
        ///  初始化一个消息队列
        /// </summary>
        /// <param name="routerKeys">routerKeys</param>
        /// <param name="hostName">hostName</param>
        public GrantMQExtend(string hostName, params string[] routerKeys)
        {
            foreach (var itemKey in routerKeys)
            {
                GrantMQManager <M> .ConsumeRegister(
                    GetRouter(itemKey, hostName),
                    GetQueue(itemKey, hostName),
                    false,
                    (MQProtocol <M> m, Exception ex) =>
                {
                    // if (ex != null)
                    // {
                    //    if (m != null)
                    //    {
                    // string msg = m.ToString();
                    // Console.WriteLine(msg);
                    // return true;
                    if (this.OnGrantMQMessageReceive != null)
                    {
                        return(this.OnGrantMQMessageReceive(m, ex));
                    }

                    // }
                    // }
                    return(false);    // 如果没有回调,不能随意删除消息
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackGroundMessageMgr"/> class.
        /// 创建接受消息实例
        /// </summary>
        /// <param name="bussinessTypes">接受消息的所有bussinessTypes</param>
        public BackGroundMessageMgr(params string[] bussinessTypes)
        {
            Task.Run(() =>
            {
                // 订阅所有的routerKey
                foreach (var item in bussinessTypes)
                {
                    GrantMQManager <SetBackGroudMessageArgs> .ConsumeRegister(
                        GetRouter(item),
                        GetQueue(item),
                        false,
                        (MQProtocol <SetBackGroudMessageArgs> m, Exception ex) =>
                    {
                        // if (ex != null)
                        // {
                        //    if (m != null)
                        //    {
                        // string msg = m.ToString();
                        // Console.WriteLine(msg);
                        // return true;
                        if (this.OnBackGroundMessageReceive != null)
                        {
                            return(this.OnBackGroundMessageReceive(m, ex));
                        }

                        // }
                        // }
                        return(false);    // 如果没有回调,不能随意删除消息
                    });
                }
            });
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the  class.
        /// 创建接受消息实例
        /// </summary>
        /// <param name="groups">接受消息的所有Ttid</param>
        /// <param name="pull">拉消息</param>
        public AuditMessageMgr(bool pull, params string[] groups)
        {
            var host = MQHostConfigManager.GetHost("Audit");

            if (host == null)
            {
                throw new Exception("RabbitMQ 没有配置  Audit 主机!!");
            }

            if (!pull)
            {
                // 订阅所有的routerKey
                foreach (var item in groups)
                {
                    GrantMQManager <T> .ConsumeRegister(
                        GetRouter(item),
                        GetQueue(item),
                        host,
                        true,
                        (MQProtocol <T> m, Exception ex) =>
                    {
                        if (this.OnAuditMessageReceive != null)
                        {
                            return(this.OnAuditMessageReceive(m, ex));
                        }
                        return(false);    // 如果没有回调,不能随意删除消息
                    });
                }
            }
            else
            {
                if (groups.Length > 0)
                {
                    Debug.Assert(true);
                }

                var item = typeof(T).Name;

                // 订阅所有的routerKey
                this._consumer = GrantMQManager <T> .PullConsumeRegister(
                    GetRouter(item),
                    GetQueue(item),
                    host,
                    true);
            }
        }