NServiceBus.Routing.MessageDrivenSubscriptions.Publishers.AddOrReplacePublishers C# (CSharp) Method

AddOrReplacePublishers() public method

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.
return void
        public void AddOrReplacePublishers(string sourceKey, IList<PublisherTableEntry> entries)
        {
            lock (updateLock)
            {
                publisherRegistrations[sourceKey] = entries;
                var newRouteTable = new Dictionary<Type, HashSet<PublisherAddress>>();
                foreach (var entry in publisherRegistrations.Values.SelectMany(g => g))
                {
                    HashSet<PublisherAddress> publishersOfThisEvent;
                    if (!newRouteTable.TryGetValue(entry.EventType, out publishersOfThisEvent))
                    {
                        publishersOfThisEvent = new HashSet<PublisherAddress>();
                        newRouteTable[entry.EventType] = publishersOfThisEvent;
                    }
                    publishersOfThisEvent.Add(entry.Address);
                }
                publishers = newRouteTable;
            }
        }

Usage Example

 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);
 }
All Usage Examples Of NServiceBus.Routing.MessageDrivenSubscriptions.Publishers::AddOrReplacePublishers