Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Upgrade Wormhole 2 to Router 3

Component: Wormhole Gateway

The NServiceBus.Wormhole package has been deprecated and replaced by the more powerful NServiceBus.Router. Each Wormhole gateway is replaced by a two-interface router that forwards messages between the transport that the endpoints use in the local site and the transport that is used to move messages between sites (e.g. Amazon SQS, Azure Storage Queues, Azure Service Bus).

Endpoint-side

The following code snippets were used to set up the Wormhole connector and send messages

var routing = endpointConfiguration.UseWormholeGateway("Gateway.SiteA");
routing.RouteToSite<MyMessage>(m => m.DestinationSite);
await endpointInstance.Send(new MyMessage
{
    DestinationSite = "SiteB"
});

The fixed or callback-based destination site configuration in the routing settings is no longer available. In order to instruct the router connector to forward a given message to a remote site, use the SendToSites extension method.

var options = new SendOptions();
options.SendToSites("SiteB");

await endpointInstance.Send(new MyMessage(), options);

Another change is that with the Router it is the sending endpoint who is, by default, responsible for providing the name of the destination endpoint via RouteToEndpoint API.

var transport = endpointConfiguration.UseTransport<LearningTransport>();
var routing = transport.Routing();

var router = routing.ConnectToRouter("Gateway.SiteA");
router.RouteToEndpoint(typeof(MyMessage), "EndpointB");

Router side

The Wormhole configuration required remote sites to be declared in the following way:

var gatewayConfig = new WormholeGatewayConfiguration
    <MsmqTransport, AzureStorageQueuesTransport>("Gateway.SiteA", "SiteA");

gatewayConfig.ConfigureRemoteSite("SiteB", "Gateway.SiteB");

In addition to that, the destination site routed had to specify forwarding for messages received from other sites:

var gatewayConfig = new WormholeGatewayConfiguration
    <MsmqTransport, AzureStorageQueuesTransport>("Gateway.SiteB", "SiteB");

gatewayConfig.ForwardToEndpoint(MessageType.Parse("MyMessage, Messages"), "EndpointB");

With the Router the transport between the routers forms a tunnel through which messages are sent when they need to be delivered to a remote site. Each router is configured with two interfaces, one for the local endpoints and the other for the tunnel.

var routerConfig = new RouterConfiguration("Gateway.SiteA");

routerConfig.AddInterface<MsmqTransport>("Local", tx => { });
routerConfig.AddInterface<AzureStorageQueuesTransport>("Tunnel", tx => { });

var staticRouting = routerConfig.UseStaticRoutingProtocol();

staticRouting.AddRoute((iface, dest) => iface == "Local", 
    "From the local site", "Gateway.SiteB", "Tunnel");

staticRouting.AddRoute((iface, dest) => iface == "Tunnel", 
    "From the remote site", null, "Local");

var router = Router.Create(routerConfig);
The is no forwarding configuration. The destination endpoint has been specified by the sending endpoint.

HTTP transports

The HTTP transport (NServiceBus.Transports.Http) is also deprecated as it was intended to be used exclusively with the Wormhole. The Router should be used with one of the cloud-native transports instead e.g. Amazon SQS, Azure Storage Queues or Azure Service Bus.


Last modified