public static UnsubscribeAction ConnectHandler <TMessage>(this IInboundMessagePipeline pipeline, Action <TMessage> handler, Predicate <TMessage> condition) where TMessage : class { return(pipeline.Configure(x => { var connector = new HandlerSubscriptionConnector <TMessage>(); return connector.Connect(x, HandlerSelector.ForSelectiveHandler(condition, handler)); })); }
/// <summary> /// Creates a MultipleHandlerSelector for the selector /// </summary> /// <typeparam name="TMessage">The message type of the handler</typeparam> /// <param name="selector">The selector to promote to a MultipleHandlerSelector</param> /// <returns>A MultipleHandlerSelector delegate for the specified message type</returns> public static MultipleHandlerSelector <TMessage> ForHandler <TMessage>(HandlerSelector <TMessage> selector) where TMessage : class { return(context => { Action <IConsumeContext <TMessage> > handler = selector(context); if (handler == null) { return Enumerable.Empty <Action <IConsumeContext <TMessage> > >(); } return Enumerable.Repeat(handler, 1); }); }
public static HandlerSelector <TMessage> ForCondition <TMessage>(HandlerSelector <TMessage> handler, Predicate <TMessage> condition) where TMessage : class { return(context => { using (context.CreateScope()) { if (!condition(context.Message)) { return null; } } return handler(context); }); }