0

I started working with NServiceBus 4 and there was a need to need to unsubscribe an event for an end point on production. In production, for subscribe assembly scanning and config file using .

So the question is how to unsubscribe? Is there an easy way to do it in production.

We thought remove the line which you subscribe to an event and hope NServiceBus update it self. However it wasn't the case after removal the subscription is still there in SQL persistence.There is official documentation to unsubscribe for version 6 and 7 however not 4.

duongthaiha
  • 855
  • 6
  • 17

1 Answers1

1

The answer Instead of remove the line which you subscribe to an event and hope NServiceBus update it self. What you have to do are:

  • Hook NServiceBus start or stop and have some code to tell NServiceBus to unsubscribe
  • Deploy the change
  • Validate the change
  • Remove the code of unsubscribe
  • Deploy again so the unsubscribe code is longer there Here is the code example:

    public class Startup : IWantToRunWhenBusStartsAndStops
    {
        private readonly IBus bus;
    
        public Startup(IBus bus)
        {
            this.bus = bus;
        }
    
        public void Start()
        {
           this.bus.Unsubscribe<EventToUnSubscribe>();
    
        }
    
        public void Stop()
        {
        }
    }
    
duongthaiha
  • 855
  • 6
  • 17