I have multiple endpoints (on different servers, from different companies) pointing at the same queue (I'm using "OverrideLocalAddress" method). When I send a message for this queue, I'm adding a header with the company ID.
I'd like to the correct endpoint to pick this message. I'm using Pipeline to filter the message I'm receiving (by company ID in the header), but just the first (a random) endpoint is getting the message.
Is there a way to every endpoint pick a message? Is there a better way to send the message to a specific endpoint?
You are using Competing Consumer
pattern, which is a great pattern!
https://www.enterpriseintegrationpatterns.com/patterns/messaging/CompetingConsumers.html https://learn.microsoft.com/en-us/azure/architecture/patterns/competing-consumers
I'm assuming you don't need messages to arrive at a specific endpoint, you need data updated in a specific database. In other words, you need multi-tenancy, which enables you to use the same codebase to provide services to different customers while minimizing the effect they have on each other.
We recently wrote a blogpost about some new features in NServiceBus to better enable this: https://particular.net/blog/multi-tenancy-support-in-sql-persistence
You should be able to provide custom code and custom connectionstrings (to specific customer databases) to enable multi tenancy. Depending on the persister you are using, that is. We have documentation for SQL Server and other persisters and also samples that explain how to inject tenant-aware components into message handlers or propagate tenant information to downstream endpoints.
I hope this helps.
UPDATE
I'm not sure this is the best solution, there might be others, but you can use SendOptions
to route to a specific logical endpoint, but also to a specific instance of an endpoint.