Content Based Routing

Version: 17.07

Supported Since: 17.01

Use case description

University XYZ, has a legacy students' result calculation service and they have decided to upgrade their system and maintain separate services for each department due to the different procedures they have to follow to calculate the GPA of the given subjects. Although there are changes in the actual back end, they do not want to introduce this dependency to the front end system and want to maintain their front end system completely independent of multiple results calculation web service end points.

Proposed Solution

University XYZ, has decided to introduce an ESB to mediate their front end calls to respective department wise back end services as shown in below diagram

content based routing diagram1

ESB will extract the relevant department based on the field in the input message and route the received message to the respective department’s result calculation endpoint. If the ESB fails to find a matching department or the received department does not have its own result calculation endpoint, then the received message will be routed to the legacy results calculation endpoint which is generic for every department, but it does not have the capability of calculating GPA value for the given subjects.

The details of the back end services of each department and the legacy results calculation service is as below,

UltraStudio Configuration

UltraESB-X Configuration

Implementation of the Solution

Prerequisite

In order to implement above use case you must first select following dependencies when you are creating an empty Ultra project

  • HTTP NIO Connector dependency from the connector list.

  • Flow Control and JSON Processors dependencies from the processor list.

If you have already created a project, you can add above dependencies via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list and Processors list, select above dependencies.
Implementation

To implement above use case, first let’s create our integration flow named “content-based-routing-flow”. Then let’s add required components by going through following steps in order.

  1. Add a HTTP Ingress Connector from the connectors list, to accept the result calculating HTTP messages. HTTP Ingress Connector should be filled as shown below to expose a single web service on port 8280 and under /service/getResults service path to calculate results using above department specific web services, and legacy web services.

  2. Add a JSON Path Extractor processing element to extract out department name from the input message. As per following input message, JSON path for the department tag should be `$.Registration.department. Let’s save the extracted value as a variable with name "Department" to use in next processing elements.

{
  "First name": "John",
  "Last name": "Carlton",
  "Registration": {
    "id": "090097G",
    "department": "Computer Science",
    "batch": "batch-09"
  },
  "Subjects": [
    {
      "id": 12295,
      "subject-code": "CS309",
      "name": "Advanced Algorithm",
      "category": "compulsory"
    },
    {
      "id": 12280,
      "subject-code": "CS103",
      "name": "Database Systems",
      "category": "compulsory"
    },
    {
      "id": 12325,
      "subject-code": "CS209",
      "name": "Computer Vision",
      "category": "optional"
    }
  ]
}
  1. Add a Switch Case processing element to check the department and select the result calculating endpoint based on the department name. This processing element should look for the value of the "Department" variable and forward the message to the respective HTTP egress connector. For this, basic parameters of this processing element should be filled as shown below.

  2. Add three Case processing elements for each possible value of the "Department" variable which should be evaluated at the Switch processing element.

  3. Add three HTTP Egress Connector elements to send messages to respective departments' result calculation service.

The completed integration flow should look like below.

content based routing complete flow

Configuration for each element is as below. The numbering corresponds to the numbers shown in above diagram.

Design View

Text View

.

1. HTTP Ingress Connector

content based routing component 1

2. JSON Path Extractor

content based routing component 2

3. Switch Processing Element

content based routing component 3

4. Case Processing Element

content based routing component 4

5. Case Processing Element

content based routing component 5

6. HTTP Egress Connector

content based routing component 6

7. HTTP Egress Connector

content based routing component 7

8. HTTP Egress Connector

content based routing component 8
.

1. HTTP Ingress Connector

Http Port

8280

Service Path

/service/getResult

2. JSON Path Extractor

Variable Name

Despatment

JSON Path

$.Registration.department

3. Switch Processing Element

Predicate Type

VARIABLE

Variable Name

Department

Variable Type

String

Predicate Function

EQUALS

4. Case Processing Element

Case Value

Electronics

5. Case Processing Element

Case Value

Computer Science

6. HTTP Egress Connector

Destination Address Type

URL

Destination Host

localhost

Destination Port

9290

Service Path

/service/getResult

7. HTTP Egress Connector

Destination Address Type

URL

Destination Host

localhost

Destination Port

9001

Service Path

/service/department/computer-science

8. HTTP Egress Connector

Destination Address Type

URL

Destination Host

localhost

Destination Port

9000

Service Path

/service/department/electronics

.

Now you can run the Ultra Project and check the functionality of the integration flow. Create an UltraESB Server run configuration and start it.

Property Configuration

In-order to run this sample in UltraESB-X distribution, no property modification is required

Navigate to $ULTRA_HOME/bin directory. Next you can run the UltraESB-X distribution with following command to start the engine with this sample project deployed.

./ultraesbx.sh -sample content-based-routing

Testing the Integration Project

After running the project, test the content based routing as per the configured values,

  • if the department value is "Computer Science", then you should be able see the message is sent out to computer science department’s endpoint by checking the message path of the UltraStudio.

  • if the department value is "Electronics", then you should be able see the message is sent out to electronic department’s endpoint by checking the message path of the UltraStudio.

  • if the department value is not specified or not equal to either of above two, then you should be able see the message is sent out to the legacy endpoint by checking the message path of the UltraStudio.

All requests must be sent to http://localhost:8280/service/getResults URL.

In this topic
In this topic
Contact Us