private Task InvokeDispatcher(MessageDispatchInfo dispatcher, IMessage message, CancellationToken cancellationToken) { if (!_logger.IsEnabled(LogLevel.Trace)) { _logger.LogDebug( $"Dispatching message Type: {message.GetType()} to Consumer: { dispatcher.ConsumerType } " + $"Method: { dispatcher.MessageHandlerMethod.Name} "); } var consumer = (IMessageConsumer)_services.GetRequiredService(dispatcher.ConsumerType); return(dispatcher.Dispatch(message, consumer, cancellationToken)); }
// Determines message dispatchers that apply to the message being published. This is optional and // specified by decorating the message handler method with attributes. private async Task <bool> PassesDispatchCriteria(MessageDispatchInfo dispatchInfo, IMessage message) { ScriptPredicate predicate = dispatchInfo.Predicate; // Run a dynamic script against the message and check the result of the specified predicate property. // This allow storing rule predicates external from the code. if (predicate != null) { return(await _scriptingSrv.SatisfiesPredicateAsync(message, predicate)); } // Check static rules to determine if message meets criteria. return(dispatchInfo.IsMatch(message)); }