Esempio n. 1
0
        /// <summary>
        /// Adds to the routing table
        /// </summary>
        /// <typeparam name="TTopic">Topic message type</typeparam>
        /// <typeparam name="TSubscriber">Transport specific <see cref="ISubscriber"/> type</typeparam>
        /// <param name="address"><see cref="IAddress"/> of the remote <see cref="IPublisher"/> for this
        /// <see cref="ISubscriber"/></param>
        public void AddTopicRouting <TTopic, TSubscriber>(IAddress address)
            where TSubscriber : ISubscriber
        {
            if (address is null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            var topicType = typeof(TTopic);

            if (topicType.GetCustomAttribute <TopicAttribute>() is null)
            {
                throw new MissingAttributeException(topicType, typeof(TopicAttribute));
            }

            var newRouting = SubscriberRouting.For <TSubscriber>(address);

            if (routingTable.TryGetValue(topicType, out var existingRouting))
            {
                if (newRouting.Address.Equals(existingRouting.Address))
                {
                    return;
                }
                else
                {
                    throw new RoutingAlreadyRegisteredException <SubscriberRouting>(newRouting, existingRouting);
                }
            }

            routingTable.Add(topicType, newRouting);
        }
Esempio n. 2
0
 /// <summary>
 /// TryGets a <see cref="SubscriberRouting"/> from the topic message type
 /// </summary>
 /// <typeparam name="TTopic">Topic message type</typeparam>
 /// <param name="routing">Outs a matching <see cref="SubscriberRouting"/> for the topic message type if the
 /// <see cref="TopicRouter"/> has one added</param>
 /// <returns>True if the <see cref="TopicRouter"/> has a <see cref="SubscriberRouting"/> for the topic message
 /// type; otherwise false</returns>
 public bool RoutingFor <TTopic>(out SubscriberRouting routing) =>
 routingTable.TryGetValue(typeof(TTopic), out routing);