Beispiel #1
0
        /// <summary>
        /// 扫描该程序集所有实现了<seealso cref="IHandler{TMessage}"/>接口的类并订阅他们
        /// </summary>
        /// <param name="mq"></param>
        /// <param name="assemblys">程序集合</param>
        /// <returns></returns>
        public static Task <IMQ> SubscibeAssemblyAsync(this IMQ mq, params Assembly[] assemblys)
        {
            if (assemblys?.Count() <= 0)
            {
                assemblys = new Assembly[] { Assembly.GetCallingAssembly() };
            }


            return(Task.Run(() =>
            {
                return mq.SubscibeAssembly(assemblys);
            }));
        }
Beispiel #2
0
        public async Task PublishMessage()
        {
            await _mq.SubscibeAsync <ClassGrade>(cg =>
            {
                this.WriteLine($"Test1_{nameof(ClassGrade)}:{cg.Id}");
            });

            await _mq.SubscibeAsync <Student>(s =>
            {
                this.WriteLine($"1:{nameof(Student)}:name={s.Name},sex={s.Sex},age={s.Age}");
            });

            await _mq.SubscibeAssemblyAsync();

            _mq.SubscibeAssembly()
            .SubscibeType <SudentHandle>();
            await _mq.SubscibeTypeAsync <SudentHandle>();

            Init();
            Thread.Sleep(5 * 1000);
        }