I'm looking to implement a simple pub-sub demo using NServiceBus
backed by Azure Service Bus.
I am working with an undetermined number of subscribers with more being spawned or existing ones being killed depending on various conditions, so every time I create a subscriber, I create an Endpoint
and an EndpointInstance
with an unique name and subscribe to the event I am interested in.
When the Subscriber shuts down, I unsubscribe from the events and Stop the EndpointInstance
.
However, if I check my Service Bus, the queue and topic subscriptions that get created in the process are not cleaned up. This means that after a while I will potentially have hundreds of queues and topic subscriptions that will never be used again due to the way I generate my EndpointInstance
names.
How do I clean those up?
Am I missing something ? should i not be creating a new Endpoint
and EndpointInstance
for every subscriber (this seems to be the pattern used in the official samples and guides).
UPDATE:
An analogy that just came to mind is something like a push notification system where clients(subscribers) come online and subscribe to the bus. When an event is published I want all online clients to receive it. When a client is shut down, I don't care about messages that are sent not am I interested in getting any lost messages when a client comes online. I want to close the subscription and clean-up the underlying infrastructure (queues, subscriptions, etc).
In my scenario, each client will define its own unique Endpoint and Endpoint instance. How do the logical endpoints come into play at this point?