AddOrReplacePublishers() публичный Метод

Adds or replaces a set of publisher registrations. The registration set is identified . If the method is called the first time with a given , the registrations are added. If the method is called with the same multiple times, the publishers registered previously under this key are replaced.
public AddOrReplacePublishers ( string sourceKey, IList entries ) : void
sourceKey string Key for this registration source.
entries IList Entries.
Результат void
 public void SetUp()
 {
     var 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);
 }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }