SzymonPobiega / NServiceBus.Router

Cross-transport, cross-site and possibly cross-cloud router component for NServiceBus
MIT License
5 stars 10 forks source link

Physical routing of MSMQ messages #12

Closed mteinum closed 4 years ago

mteinum commented 5 years ago

Hi!

We have this setup

machines: A, B and C.

Machine Description
A dotnet core running in docker using rabbitmq as transport
B Router, with two interfaces: rabbitmq and MSMQ
B Endpoint, Bar (.NET Framework)
C Endpoint, Foo (.NET Framework)

Sending BarCommand from A via B Router to B Bar endpoints works great.

How can A send FooCommand to C (Foo) via B?

I have tried: 1.

bridge.RouteToEndpoint(typeof(FooCommand), "Foo@C");

but this fails with invalid address

  1. instance-mapping.xml in the router project.
routerConfig.AddInterface<MsmqTransport>("MSMQ", t => {
  t.Routing().InstanceMappingFile().FilePath("instance-mapping.xml");
});
<?xml version="1.0" encoding="utf-8" ?>
<endpoints>
  <endpoint name="Foo">
    <instance machine="C"/>
  </endpoint>
</endpoints>

But the router still delivers FooCommand to its local machine Foo@B

SzymonPobiega commented 5 years ago

Hi

Please try following code in the router config:

var msmqIface = routerConfig.AddInterface<MsmqTransport>("MSMQ", t => {});
msmqIface.EndpointInstances.AddOrReplaceInstances("code-config", new List<EndpointInstance>()
{
   new EndpointInstance("Foo", null).AtMachine("C")
});

This should instruct the MSMQ transport to use machine C properly. The InstanceMappingFile API, although attached to the transport config, requires full NServiceBus as it is based on features which Router does not recognise. You need to use the lower level EndpointInstances API.

robj-applied commented 4 years ago

Hi Szymon,

I've been trying this exact scenario with your recommended code and for me, it still creates the message on the same machine that the router is on, rather than the remote machine (machine "C" in the example above).

Can I confim, what does the "code-config" bit do? I've copied it verbatim but perhaps wondering if I shouldn't have. Here's my router code for clarity:

const string sagaMsmqInterfaceName = "SAGA_MSMQ_INTERFACE";

var sagaMsmqInterface = routerConfig.AddInterface<MsmqTransport>(sagaMsmqInterfaceName, extensions => { });

var appServerSaga = new EndpointInstance(SagaEndpointName, null);
appServerSaga.AtMachine("REMOTE-MACHINE-NAME");

sagaMsmqInterface.EndpointInstances.AddOrReplaceInstances("code-config", new List<EndpointInstance>
{
    appServerSaga
});

sagaMsmqInterface.EnableMessageDrivenPublishSubscribe(CreateSqlSubscriptionStorage());
sagaMsmqInterface.AutoCreateQueues();

Using NServiceBus 7.2.2, and NServiceBus.Router 3.6.0

robj-applied commented 4 years ago

I've redone this using fresh endpoint names and now it works. Something must have got itself confused along the way.

SzymonPobiega commented 4 years ago

Hey hey. Sorry for the late reply. I was at a conference for last couple of days. Glad that it works now :)

robj-applied commented 4 years ago

No worries! Solved a fairly major problem so thanks for the original response :)