Contents
|
Introduction To The NServiceBus Gateway
This post, together with The Gateway & Multi-Site Distribution with NServiceBus post will, give you a high level overview of what the NServiceBus gateway is, where to use it and perhaps more importantly where to not use it. The main purpose of the gateway is to allow you to do the same durable fire and forget messaging that NServiceBus has got you used to across physically separated sites, the meaning of "sites " is locations where you run IT infrastructure and not web sites. The gateway only comes into play where you can’t use the regular queued transports for communication i.e. when setting up a VPN-connection is not an option. The reason for not using a VPN is usually security concerns, bandwidth limitation, latency problems, high availability constraints etc. When to not use the GatewayThe gateway should not be used when the reason for running separated sites is
disaster recovery. So, if your sites are logically similar use one of the approaches above, if they are logically different, the Gateway may come handy. What are logically different sites?Logically different sites mean sites that serve a different business purpose, i.e. differs in behavior from other sites. Looking at this scenario from a logical view we see that all the communication goes on within the same business service (BS), pricing in this case.
Prices are usually set for a least a day at a time so it’s good enough for the HQ to push them to the sites once per day, lets model this as a DailyPriceUpdates message containing the list of price updates for the coming business day. Given this design we only need to get one message across to each site per day which lowers the requirement for the infrastructure used.
As you can see the prices gets pushed daily to the stores and sales reports are pushed daily to the HQ. Any pub/sub needed goes on within the same physical site and this is the reason that the NServiceBus gateway doesn’t support pub/sub across sites since it shouldn’t be needed in a well designed system.
Using the gatewayBeginning version 3 of NServiceBus, the gateway is included in the core assembly and that means that every endpoint is capable to running a gateway. /// <summary> /// Sends the messages to all sites with matching /// site keys registered with the gateway. /// The gateway is assumed to be located at the master node. /// </summary> /// <param name="siteKeys"></param> /// <param name="messages"></param> /// <returns></returns> ICallback SendToSites(IEnumerable<string> siteKeys, params object[] messages); As you can see this allows you to pass in a list of sites to where you want to send your messages. Each site can be configured to use a different transport mechanism. On the receiving side there will be another gateway listening on the input channel and forward the incoming message to the target endpoint. The image below shows the physical parts involved: As can be seen form the image above, there is a gateway running inside of each host process. The gateway has the following features:
Where to go from here?You can find a working sample at the NServiceBus/Samples/Gateway folder. Feel free to read our other post about the Gateway: Key thing to take away
This article was written by Andreas Öhlund and the original blog post can be found here. |

