Exemplo n.º 1
0
        public bool SendMessage(MQProtocol <M> message, string hostName)
        {
            var routeKey = GetRouter(message.RouterKey, hostName);
            var host     = MQHostConfigManager.GetHost(hostName);

            return(GrantMQManager <M> .Publish(message, routeKey, host));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存异步消息,并设置初始处理状态
        /// </summary>
        /// <param name="valueArgs">参数</param>
        /// <returns>是否成功</returns>
        public static bool SetMessage(T valueArgs)
        {
            if (valueArgs == null)
            {
                return(true);
            }

            var msg      = new MQProtocol <T>("AuditMessage", valueArgs, Guid.NewGuid().ToString("N"));
            var routeKey = GetRouter(valueArgs.Ttid);
            var host     = MQHostConfigManager.GetHost("Audit");
            var mq       = GrantMQManager <T> .Publish(msg, routeKey, host);

            return(mq);
        }
Exemplo n.º 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);
            }
        }