Tags

Introduction

Routing => Take the other way

Hello, everyone!

I will start this article in a different manner today. Let me start with a small scenario – I hope you remember the old style cinema theatres where one person would check our tickets and direct us to take a left side or right side of the seating, based on the type of the ticket we bought.
Another example like this is –  You are actually entering your office premises by car. According to the block/area/company you work in, you are told to park your vehicles in a particular location. Please note that your seating area will differ according to the class/number of a ticket you purchase. Also, your parking area will differ according to your company. So, the point here is that based on the content you own, whether ticket or company, you are routed to a particular location. Let’s discuss routing in the computer world.

Routing

Routing service will act as a Central Router or Message Router which receives the messages from the client and routes the messages to the appropriate service, based on the message content client provides. Routing Service will act as a front-end service to the client, receive the message, apply the filter,  and route the messages to the back-end services.
Routing
In the above figure, you can see that the Routing Service is an intermediary between the client and the services. The primary job of Routing Service is to route the client messages to the back-end services. Routing service is implemented as a WCF service in the System.ServiceModel.Routing assembly.

Need of Routing

You may wonder why we need to pass the messages via Routing Service,  or,  why can’t we simply pass the messages directly to the back-end services?

To answer this, Routing Service aggregates (collective) multiple destination endpoints to reduce the number of endpoints exposed to the client applications. So, the client will be having only one destination endpoint and send messages to the Routing service. Then, the Routing Service will redirect the messages, based on their content, to the respective services. Another benefit of this is that some sorts of operations have to be processed only by the particular service. For example, all tax calculations have to be processed only by the service A.

Service Aggregation

Clients do not need to remember all the Service URL’s to get it served. Only Routing Service URL needs to be remembered and it will have the complete collection of back-end services

Service Versioning

Imagine you have to migrate the existing service to the new service. So, you are in the situation to maintain the different versions over a period of time. Of course, the customer should be able to utilize the existing features in the old version of the service and the new features in the new version of the service. For that, Routing Service plays a very important role in redirecting messages according to the version information in the messages from the client.

Priority Routing

There are some scenarios like, specific clients requests (e.g. – Admin Requests) have to be processed in a separate service among other clients requests(Eg: Normal user Requests), to segregate a particular client request and process it in a separate service, routing would be an ideal option, by using a filter in routing service that looks for client specific information contained in the message and redirects the request to the appropriate service to get it processed.

Error Handling

This would be used in a situation like, though our main service gets affected/crashed/not reachable, the backup service will take care of managing the errors/exceptions.

Protocol and Security Bridging

Imagine you have a legacy service which could use only HTTP protocol, but in your recent service version, it supports multiple protocols. To integrate the old legacy service into the new version which enables users to get the support of all the protocols., Routing service (Legacy Service) will communicate with the back end services with a different protocol and reply to the client in a different protocol.
Routing
Dynamic Configuration

There are a few applications which should run 24X7 time frame without any interruptions. It’s not fair to stop these applications and modify the configuration as it will be a huge impact to the customer. For these sets of scenarios, Routing service provides an IExtension<T> implementation called Routing Extension which allows dynamic update of Routing Service configuration at run time.

In my next article, we shall see how to configure routing in WCF with detailed steps and source code.

Summary

Routing Service works in the System.ServiceModel.Routing Namespace. Routing service aggregates one or more service endpoints and routes the messages based on the message content which comes from the client.

Advertisements