RegisterPublisher() issue

Hi Everyone, I am trying to register a publisher which works fine if the publisher is on the same machine as the subscriber. I need to register the publisher on a different server. How can I do this? I saw a discussion back in Feb of last year: Logical to Physical mapping but I don’t think anything came of it regarding an API change. I couldn’t find an example of how to do this. I’m using NSB v6.3.4

var transport = endpointConfiguration.UseTransport<MsmqTransport>();

var routing = transport.Routing();
routing.RegisterPublisher(
    assembly: typeof(OrderAccepted).Assembly,
    publisherEndpoint: "Sales");

Hi Leonard

The RegisterPublisher API defines the logical publisher registration. That’s why you can’t declare the publisher at a given machine in the following format sales@machinename To define the physical routing with MSMQ we recommend you to use the instance mapping file. For further documentation refer to

<endpoints>
  <endpoint name="Sales">
    <instance machine="VM-1"/>
  </endpoint>
</endpoints>

We also have a sample about the instance mapping usage

I hope that helps

Regards
Daniel

Hi Daniel, our environment is pretty much completely database driven with regards to endpoint configuration. Is there any way to programmatically do this setup without instance mapping files? Logical to Physical mapping via the API would be great but I can’t seem to find an example.

Hi Leonard

You can dynamically load routing entries. The routing API has a bunch of extension points for Command and Event Routing.

we even have a sample which shows how to extend it

https://docs.particular.net/samples/routing/custom/

I hope that helps

Regards
Daniel

Thanks Daniel. Wow that is crazy complicated to do something that should be ‘easy’. Adding 200+lines of code to my project which I don’t fully understand is not a good recipe for maintaining it in the future. I settled on dynamically creating the instance mapping file on startup and that solved my issue. I am sure there is a good architectural reason for this, but this is something that shouldn’t be rocket science. :grinning:

Hey @Leonard_Riotto,

If you have all the required routing information already stored in a database, using the “advanced routing API” as described in Routing system extensibility points • NServiceBus • Particular Docs shouldn’t be that difficult. The sample Daniel mentioned is indeed a bit more complex, but also does quite a bit more than just loading data from the database.

We can arrange a call to walk you quickly through the required API usage to load your routing information dynamically from the database if you’re interested. I think this approach would actually be easier than dynamically create the instance mapping file :slight_smile: