Exemple #1
0
        public void When_same_publisher_is_registered_multiple_times_should_remove_duplicates()
        {
            var publisherTable = new Publishers();

            var pub1 = PublisherAddress.CreateFromEndpointName("Endpoint1");
            var pub2 = PublisherAddress.CreateFromEndpointName("Endpoint1");
            var pub3 = PublisherAddress.CreateFromEndpointInstances(new EndpointInstance("Instance1"), new EndpointInstance("Instance2"));
            var pub4 = PublisherAddress.CreateFromEndpointInstances(new EndpointInstance("Instance1"), new EndpointInstance("Instance2"));
            var pub5 = PublisherAddress.CreateFromPhysicalAddresses("address1", "address2");
            var pub6 = PublisherAddress.CreateFromPhysicalAddresses("address1", "address2");

            publisherTable.AddOrReplacePublishers("key2", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), pub1),
                new PublisherTableEntry(typeof(MyEvent), pub2),
                new PublisherTableEntry(typeof(MyEvent), pub3),
                new PublisherTableEntry(typeof(MyEvent), pub4),
                new PublisherTableEntry(typeof(MyEvent), pub5),
                new PublisherTableEntry(typeof(MyEvent), pub6)
            });

            var pubs = publisherTable.GetPublisherFor(typeof(MyEvent)).ToArray();

            Assert.AreEqual(3, pubs.Length);
            Assert.Contains(pub1, pubs);
            Assert.Contains(pub2, pubs);
            Assert.Contains(pub3, pubs);
            Assert.Contains(pub4, pubs);
            Assert.Contains(pub5, pubs);
            Assert.Contains(pub6, pubs);
        }
    async Task UpdateCaches(EndpointInstance instanceName, Type[] handledTypes, Type[] publishedTypes)
    {
        var newInstanceMap  = BuildNewInstanceMap(instanceName);
        var newEndpointMap  = BuildNewEndpointMap(instanceName.Endpoint, handledTypes, endpointMap);
        var newPublisherMap = BuildNewPublisherMap(instanceName, publishedTypes, publisherMap);

        LogChangesToEndpointMap(endpointMap, newEndpointMap);
        LogChangesToInstanceMap(instanceMap, newInstanceMap);
        var toSubscribe = LogChangesToPublisherMap(publisherMap, newPublisherMap).ToArray();

        #region AddOrReplace

        routingTable.AddOrReplaceRoutes("AutomaticRouting", newEndpointMap.Select(
                                            x => new RouteTableEntry(x.Key, UnicastRoute.CreateFromEndpointName(x.Value))).ToList());

        publishers.AddOrReplacePublishers("AutomaticRouting", newPublisherMap.Select(
                                              x => new PublisherTableEntry(x.Key, PublisherAddress.CreateFromEndpointName(x.Value))).ToList());

        endpointInstances.AddOrReplaceInstances("AutomaticRouting", newInstanceMap.SelectMany(x => x.Value).ToList());

        #endregion

        instanceMap  = newInstanceMap;
        endpointMap  = newEndpointMap;
        publisherMap = newPublisherMap;

        foreach (var type in toSubscribe.Intersect(messageTypesHandledByThisEndpoint))
        {
            await messageSession.Subscribe(type)
            .ConfigureAwait(false);
        }
    }
 public void SetUp()
 {
     publishers = new Publishers();
     publishers.AddOrReplacePublishers("A", new List <PublisherTableEntry> {
         new PublisherTableEntry(typeof(object), PublisherAddress.CreateFromPhysicalAddresses("publisher1"))
     });
     router              = new SubscriptionRouter(publishers, new EndpointInstances(), i => i.ToString());
     dispatcher          = new FakeDispatcher();
     subscribeTerminator = new MessageDrivenSubscribeTerminator(router, "replyToAddress", "Endpoint", dispatcher);
 }
Exemple #4
0
        public void When_group_exists_should_replace_existing_routes()
        {
            var publisherTable = new Publishers();
            var oldPublisher   = PublisherAddress.CreateFromEndpointName("Endpoint1");
            var newPublisher   = PublisherAddress.CreateFromEndpointName("Endpoint2");

            publisherTable.AddOrReplacePublishers("key", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), oldPublisher),
            });

            publisherTable.AddOrReplacePublishers("key", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), newPublisher),
            });

            var retrievedPublisher = publisherTable.GetPublisherFor(typeof(MyEvent)).Single();

            Assert.AreSame(newPublisher, retrievedPublisher);
        }
Exemple #5
0
        public void When_multiple_publishers_exist_should_return_all_of_them()
        {
            var publisherTable = new Publishers();

            var pub1 = PublisherAddress.CreateFromEndpointName("Endpoint1");
            var pub2 = PublisherAddress.CreateFromEndpointName("Endpoint2");

            publisherTable.AddOrReplacePublishers("key2", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), pub1),
            });
            publisherTable.AddOrReplacePublishers("key1", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), pub2),
            });

            var pubs = publisherTable.GetPublisherFor(typeof(MyEvent)).ToArray();

            Assert.Contains(pub1, pubs);
            Assert.Contains(pub2, pubs);
        }
        internal void Apply(Publishers publishers, UnicastRoutingTable unicastRoutingTable, Func <string, string> makeCanonicalAddress, Conventions conventions)
        {
            var routeTableEntries     = new Dictionary <Type, RouteTableEntry>();
            var publisherTableEntries = new List <PublisherTableEntry>();

            foreach (var m in this.Cast <MessageEndpointMapping>().OrderByDescending(m => m))
            {
                m.Configure((type, endpointAddress) =>
                {
                    if (!conventions.IsMessageType(type))
                    {
                        return;
                    }
                    var canonicalForm = makeCanonicalAddress(endpointAddress);
                    var baseTypes     = GetBaseTypes(type, conventions);

                    RegisterMessageRoute(type, canonicalForm, routeTableEntries, baseTypes);
                    RegisterEventRoute(type, canonicalForm, publisherTableEntries, baseTypes);
                });
            }

            publishers.AddOrReplacePublishers("MessageEndpointMappings", publisherTableEntries);
            unicastRoutingTable.AddOrReplaceRoutes("MessageEndpointMappings", routeTableEntries.Values.ToList());
        }
        public void Apply(Publishers publishers, Conventions conventions, bool enforceBestPractices)
        {
            var entries = publisherSources.SelectMany(s => Generate(conventions, s, enforceBestPractices)).ToList();

            publishers.AddOrReplacePublishers("EndpointConfiguration", entries);
        }
 public void Apply(Publishers publishers, Conventions conventions, bool enforceBestPractices)
 {
     var entries = publisherSources.SelectMany(s => Generate(conventions, s, enforceBestPractices)).ToList();
     publishers.AddOrReplacePublishers("EndpointConfiguration", entries);
 }
        internal void Apply(Publishers publishers, UnicastRoutingTable unicastRoutingTable, Func<string, string> makeCanonicalAddress, Conventions conventions)
        {
            var routeTableEntries = new Dictionary<Type, RouteTableEntry>();
            var publisherTableEntries = new List<PublisherTableEntry>();

            foreach (var m in this.Cast<MessageEndpointMapping>().OrderByDescending(m => m))
            {
                m.Configure((type, endpointAddress) =>
                {
                    if (!conventions.IsMessageType(type))
                    {
                        return;
                    }
                    var canonicalForm = makeCanonicalAddress(endpointAddress);
                    var baseTypes = GetBaseTypes(type, conventions);

                    RegisterMessageRoute(type, canonicalForm, routeTableEntries, baseTypes);
                    RegisterEventRoute(type, canonicalForm, publisherTableEntries, baseTypes);
                });
            }

            publishers.AddOrReplacePublishers("MessageEndpointMappings", publisherTableEntries);
            unicastRoutingTable.AddOrReplaceRoutes("MessageEndpointMappings", routeTableEntries.Values.ToList());
        }