/// <summary> /// 添加consumer /// 消费者停止消费消息后,将异常抛出,让消息回滚至原队列中 /// 等待下次处理 /// </summary> /// <typeparam name="TEvent">consumer的接收事件参数</typeparam> /// <typeparam name="TConsumer">consumer类型</typeparam> /// <param name="cfg">配置对象</param> /// <param name="handlerType">处理类型</param> protected void ConsumerTo <TEvent, TConsumer>(SubscriptionBusServiceConfigurator cfg, Type handlerType) where TConsumer : IEventConsumer <TEvent> where TEvent : Event { cfg.Handler <TEvent>(evnt => { try { if (_beforeConsumer != null) { _beforeConsumer.Execute(evnt); } _locator.GetInstance <TConsumer>().Consume(evnt); if (_afterConsumer != null) { _afterConsumer.Execute(evnt); } } catch (StopedConsumeException) { throw; } catch (Exception ex) { Log.Write(string.Format("执行{0}错误", typeof(TConsumer)), MessageType.Error, this.GetType(), ex); } }).Permanent(); }