示例#1
0
        public List <BaseCommandHandler> GetCurrentSubscriptions(object message, RoutingFilter filter = null)
        {
            var latestSubscriptions  = GetCurrentSubscriptions();
            var msgTypeInfo          = message.GetType().GetTypeInfo();
            var filteredSubscription = new List <BaseCommandHandler>();

            for (var idx = 0; idx < latestSubscriptions.Length; idx++)
            {
                var subscription = latestSubscriptions[idx];

                if (!subscription.MessageType.IsAssignableFrom(msgTypeInfo))
                {
                    continue;
                }

                if (!subscription.IsFilterMatch(message, filter))
                {
                    continue;
                }

                filteredSubscription.Add(subscription);
            }

            return(filteredSubscription);
        }
        public async Task <R> QueryAsync <T, R>
        (
            T message,
            RoutingFilter filter = null,
            CancellationToken cancellationToken = default,
            BehaviorChain behaviors             = null
        )
        {
            var localSubscriptions = GetSubscriptors(message, filter).OfType <IAsyncCommandHandler>();

            if (!localSubscriptions.Any())
            {
                return(default);
示例#3
0
        private Guid RegisterCore(Type messageType, object action, RoutingFilter filter)
        {
            var type         = messageType;
            var key          = Guid.NewGuid();
            var subscription = new CommandHandler(type, key, action, filter);

            lock (_allSubscriptions)
            {
                _allSubscriptions.Add(subscription);
                _subscriptionRevision++;
            }

            return(key);
        }
示例#4
0
        internal Guid RegisterAsync <T>(Func <IMessageEnvelope <T>, Task> action, RoutingFilter filter)
        {
            var type         = typeof(T);
            var key          = Guid.NewGuid();
            var subscription = new AsyncCommandHandler(type, key, action, filter);

            lock (_allSubscriptions)
            {
                _allSubscriptions.Add(subscription);
                _subscriptionRevision++;
            }

            return(key);
        }
示例#5
0
        public bool EvaluateFilter(object message, RoutingFilter messageFilter)
        {
            // If routing key is defined on subscription we check if it is match with message key
            // If Subscriber or sender use * we skip routing key comparison
            if (!string.IsNullOrWhiteSpace(RoutingKey) && !RoutingKey.InvariantEquals(messageFilter?.RoutingKey) && messageFilter?.RoutingKey != "*" && RoutingKey != "*")
            {
                return(false);
            }

            // If subscription have routing attributes
            if (RoutingAttributes.Count > 0)
            {
                // If message is IPropertiesSource we check properties from message directly
                if (message is IPropertySource propertiesSource)
                {
                    foreach (var attribute in RoutingAttributes)
                    {
                        if (!propertiesSource.ContainsProperty(attribute.Key))
                        {
                            return(false);
                        }

                        if (!propertiesSource[attribute.Key].InvariantEquals(attribute.Value))
                        {
                            return(false);
                        }
                    }
                }

                // if we have additional routing attributes in message filter
                if (messageFilter?.RoutingAttributes?.Count > 0 && !RoutingAttributes.IsEqual(messageFilter.RoutingAttributes))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#6
0
        internal Guid Register(Type messageType, Func <Delegate> action, RoutingFilter filter)
        {
            //ValidateDelegate(messageType, action);

            return(RegisterCore(messageType, action, filter));
        }
示例#7
0
 internal Guid Register <T>(Action <IMessageEnvelope <T> > action, RoutingFilter filter)
 {
     return(RegisterCore(typeof(T), action, filter));
 }
 public List <BaseCommandHandler> GetSubscriptors(object message, RoutingFilter filter = null)
 {
     return(_subscriptions.GetCurrentSubscriptions(message, filter));
 }