Exemple #1
0
        /// <summary>
        ///     单 MQ 处理
        /// </summary>
        /// <param name="config"></param>
        public static void RegisterSingleMqProcess <TMsmqHandlerContract, TMsmqHandlerImpl>(MsmqProcessConfig config)
            where TMsmqHandlerImpl : class, TMsmqHandlerContract, new()
        {
            ThrowHelper.ThrowIfNull(config, "config");

            var msmqBindObject = MsmqBindUtils.Register <TMsmqHandlerContract, TMsmqHandlerImpl>();

            RegisterSingleMqProcess(config, msg => { msmqBindObject.Execute(msg); });
        }
        /// <summary>
        ///     初始化 契约缓存
        /// </summary>
        public void InitContractCache()
        {
            var           cType          = typeof(TMsmqHandlerContract);
            ParameterInfo tParameterInfo = null;
            var           methods        = cType.GetMethods(BindingFlags.Public | BindingFlags.Instance)
                                           .Where(x => x.MemberType == MemberTypes.Method && //实例方法
                                                  x.ReturnType == typeof(void) && //方法无返回值
                                                  x.GetParameters().Length == 1 && //一个参数
                                                  (tParameterInfo = x.GetParameters()[0])
                                                  .ParameterType.IsSubclassOf(typeof(MessageBase))) //参数继承自 MessageBase
                                           .ToDictionary(x => x.Name, y => y);

            m_MsmqContract_Cache.AddRange(methods);

            MsmqHandlerFactory = MsmqBindUtils.GetNewFactory <TMsmqHandlerImpl>();
        }