Skip to content

Service Routing Tables Sample

The service Routing tables provide a very low latency way of implementing basic Neuron ESB scenarios of mocking, mapping, and routing services without the overhead of a business process. Though business processes are far more customizable, it has an overhead because of all the messaging context available in the Business Process to customize message processing.

In the service routing table, you can include one or more service endpoints and then associate the service routing table with a client connector. When configured this way, all calls to the client connector are routed to the backend service endpoint configured in the service routing table.

Some simple use cases shown in this sample can be implemented with zero coding using this new feature.

Overview

This sample shows how you can implement various use cases commonly needed in setting up Service Oriented Architecture and Microservices architecture.

Setup

If not already open, open the Visual Studio solution RoutingAndTracingWCF.sln located at: <Neuron ESB Install Folder>\Samples\Services\RoutingAndTracingWCF. This solution is configured to run with two startup projects:

  • OrderQuoteServiceHost
  • RoutingAndTracingREST

These provide a simulation of SOAP and REST services. The Neuron ESB Configuration is setup with service endpoints to invoke these services from Neuron ESB. There are three service endpoints setup in this configuration:

  • Order_Local – WCF service endpoint to illustrate conditional service routing table
  • Order_National – Another WCF service endpoint to illustrate conditional service routing table
  • OrderQuoteService_REST – A sample REST service to invoke from service routing tables that call a REST service.

The remaining service endpoints are client connectors. They are described in detail in the section Use Cases. To test the client connectors, you will need a tool like Postman to invoke HTTP GET and HTTP POST methods against the URLs defined in the respective client connector.

Open and Start the Neuron ESB Configuration

The configuration used for this sample is named ServiceRoutingTablesSample. If you haven’t ready opened and started the Neuron ESB configuration, see the article Using the Neuron Samples to get started.

This sample requires a Neuron ESB database be configured. The configuration already includes a database; you need to create the database and configure the security to ensure that Neuron ESB runtime has access. To create the database, in Neuron ESB Explorer, navigate to Deployment->Databases. There is already a database configured for the local machine, using a non-SQL Server Express Edition. If you’re using SQL Server Express, change the server accordingly (i.e., .\SQLExpress). Set or select the database “NeuronESBSampleDB.” Modify the Server property to match your database server and edition. Click the Test/Create button to create the database on the server specified:

After the database is created, click on the Security tab and add the account that the Neuron ESB runtime is configured to use (i.e., SYSTEM). Click the Apply button when you are done:

Repository

Several Items are provided in the repository to support data mapping and testing.

XML Schemas

  • Order Quotes Schema.

JSON Schemas

  • OrderResponseSchema
  • OrderSchema
  • QuoteSchema

Data Mapper

  • JSON_TO_XML_For_Order
  • JSON_TO_XML_For_OrderResponse
  • XML_TO_JSON_For_Order
  • XML_TO_JSON_For_OrderResponse

XML Documents

  • SOAPRequest_GetOrders
  • SOAPRequest_GetOrders_Parameters

JSON Documents

  • Orders
  • Quotes

WSDL Documents

  • OrderQuoteService_Local
  • OrderQuoteService_National

Service Routing Tables

There are several service routing tables defined for this configuration. They can be found by selecting Connections –> Service Routing Tables in the Neuron ESB Explorer navigation:

Select a Service Route to see its details:

Click the Configure Endpoint button to see the routing properties for the select endpoint:

The Service Routing Table definition has five tabs:

  • Headers – Add HTTP Headers to the outgoing request message
  • Body – Set properties of the outgoing message body and optionally apply Data Maps to the outgoing request and/or incoming response
  • URL Parameters (query string) – Add Query String parameters to the URL
  • Test – Set up a mock response
  • Settings – This tab is for runtime settings. Not used in this sample

You can apply conditions to the select endpoints, restricting which requests messages are routed to each one. The conditions can be viewed by clicking the Condition button in the Routing table details. This button is next to the condition in the lower right section, as shown on the screen below.

The Condition editor opens when you click the button. Use the dropdowns to see the conditions you can define:

Use Cases

The following use cases illustrate each service routing table and the client connector associated with it. For each use case, open the service routing table and click the Configure Endpoint button to see the definition in each tab. The instructions for testing the Service Routing Tables are in the section Testing Services with Postman and Fiddler at the end of this document.

Pass Thru

This scenario forwards the incoming requests to the back-end service. This type of scenario is common when implementing Neuron ESB for endpoint management. With this type of implementation, the Neuron ESB Client applications can continue to function without interruption when back-end service address changes or additional mapping needs to be added to call back end service after initial implementation.

Client Connector – ServiceRouteTables_SOAP_SOAP_Passthru

Service Routing Table – Routing_Passthru

Mock Request

When testing services, sometimes Neuron ESB client application needs to test the integration, but it is not ready to create a request with all the required back-end parameters. In this case, the Service Routing Table can send a hard-coded pre-configured request to the back-end service and return response to the client.

Client Connector – ServiceRouteTables_MockRequest
Service Routing Table – Routing_Mock_Request

Mock Response

When testing services, sometimes Neuron ESB client application needs to test the integration, but the back-end service is not ready to send the response required by the client application. In this case, the Service Routing Table can send a hard-coded pre-configured response without ever calling the back-end service.

Client Connector – ServiceRouteTable_Mock_Response
Service Routing Table – Routing_Mock_Response

REST to SOAP

Web services in many organizations are implemented as WCF or SOAP services. The modern trend with browser and Java-script based applications is to use REST protocol. Service Routing tables associated with Data Mappers can provide REST to SOAP Service requests and response mapping.

Client Connector – ServiceRouteTables_REST_SOAP
Service Routing Table – ServiceRoutingTable_REST_SOAP

SOAP to REST

Many times back-end web services upgrade to REST protocol. Still, some traditional Neuron ESB Client applications configured with WCF proxy are not ready to start consuming the web service using the REST protocol. In this case, the Service Routing Tables associated with Data Mappers can provide SOAP to rest service requests and response mapping.

Client Connectors – ServiceRouteTables_SOAP_REST, ServiceRouteTables_SOAP_REST_GET
Service Routing Tables – ServiceRoutingTable_SOAP_REST, ServiceRoutingTable_SOAP_REST_GET

Conditional

A common scenario found in Service Oriented Architecture is routing requests to different service endpoints depending on message content or some header or query string values. We ship a sample for this scenario using a Business Process. In this version, simple scenarios can be implemented using a Service Routing Table with associated conditions.

This sample uses the condition “Body Contains New York” or “Body Contains Los Angles” for illustration. More complex conditions can be implemented. Keep in mind that very complex condition evaluation adds latency.

Client Connector – ServiceRouteTables_Conditional
Service Routing Table – Routing_Conditional

Query string

Sometimes when calling external services, an API key needs to be appended as a query string. With this setup, it is not necessary to share the API key with Neuron ESB client applications. The service routing table can append the additional query string.

Sometimes traditional asmx services that accept parameters as query string need to be converted to search engine-friendly Restful URLs. In this case, the query strings required by a backend service can be mapped to the local path of the incoming request.

Client Connector – ServiceRouteTables_QueryString
Service Routing Table – ServiceRoutingTable_QueryString_Header

Headers

Sometimes custom headers need to be added to the back-end service call, but Neuron ESB client applications do not have the customization needed for adding them. For example, a WCF proxy requires a custom WCF behavior to add headers to the backend service call.

Client Connector – ServiceRouteTables_HttpHeader
Service Routing Table – ServiceRoutingTable_Add_Header

Testing Services with Postman and Fiddler

Postman is an excellent tool for testing REST-based APIs. If you don’t already have Postman installed, you can download it from here:

https://dl.pstmn.io/download/latest/win64

A postman collection file named “Neuron Service Routing Table Samples” is provided in the samples folder located at <Neuron ESB Install Folder>\Samples\Configurations\ServiceRoutingTablesSample. You can import a Postman collection by clicking File->Import

Click the Upload Files button and navigate to and select the file <Neuron ESB Install Folder>\Samples\Configurations\ServiceRoutingTablesSample\Neuron Service Routing Table Samples.json. Click the Import button to import the collection into Postman:

With Postman, you specify the method and client connector address. You set the body in the body section and select the appropriate body type (XML for SOAP and JSON for REST services in this example). You can find the test message examples in the repository under XML documents and JSON Documents.

Each request in this collection is pre-configured with the Neuron ESB Client Connector URL, any required headers, and sample request body values (if needed). You can execute various requests in the collection by clicking Send button on the request and checking the response values.

You can use Postman to test REST services as well as SOAP services that use basic http binding. For testing SOAP services using Postman see this tutorial:

https://learning.postman.com/docs/sending-requests/supported-api-frameworks/making-soap-requests/

Was this article helpful?
Dislike 0
Previous: Scheduler Custom Job Sample