How to overwrite an observer?

I have tried setting in my di.xml:

 <preference for="Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver"

Isn’t it possible to do this for an observer? I do not just want to listen to the event, I need to change the existing code, because it connects to an external service and I need to avoid double connections to it.

Thanks for your help :slight_smile:

OK it turned out that the module should also be enabled while testing this. :dizzy_face:

At least I can tell you that the preference node will work for overwriting an observer.