Wednesday, September 14, 2016

Using Dynamic Routing in Oracle Service Bus

Oracle's flagship Enteprise Service Bus - Oracle Service Bus (OSB) - is based on the following conceptions:
  • Business Service wires a service provider to the bus

  • Proxy Service wires a service consumer to the bus

  • Message Flow connects a ProxyService to a single or multiple business services. Some message flows may be very complicated and contain routing, transformation, parallel execution and other actions. Physically a message flow is specified inside a proxy service.

Let's learn how to configure the Dynamic Routing action. Dynamic routing is a kind of the Content-based Routing pattern, which is used when the BusinessService endpoint is required to be determined at run time, an alternative to Static Routing, which is used when the BusinessService endpoint is established during design time.

Creating the required business services

For demonstration pupose, let's define, leveraging Oracle SOA Suite, two simple services: the SomeServiceRu service that accepts only requests for Russia and the SomeServiceEng that accepts international requests. Each service is created as an JDeveloper project and based upon a corresponding BPEL-process. The processes manipulate with messages defined by the following schema:

Every BPEL process is a part of the following composite application:

The processes are trivial: a response messages containing the ENG string literal is returned by SomeServiceEng, and the RU message is returned by SomeServiceRu respectively.

Creating an OSB demo project in Oracle Enterprise Pack for Eclipse

To configure dynamic routing, a new project named for example CountryRouter should be created. Two business services have to be defined within the project: in order to connect to SomeServiceEng and in order to connect to SomeServiceRu. The Dynamic Routing action has to be placed inside the CountryProxyService.proxy ProxyService.

A couple of words about the creation of the proxy service.

Firstly, a WSDL definition of the service should be created. Eclipse contains a standard master for generating WSDL definitions. The master is available by the File -> New -> WSDL menu item.

1. The path to the WSDL and its name should be specified.

2. The WSDL Skeleton for SOAP will be created. A target namespace and the prefix have to be specified as well.

The content of the WSDL definition for the proxy service is shown in the following diagram:

Currently the proxy service may be created. The WSDL Web Service is the service type and the created before file CountryProxyService.wsdl is the definition of the service.

The Message Flow tab is the place where the service logic is configured. The Route node has to be added to the message flow, and then the Dynamic Routing action has to be placed into the node.

The parameters of the dynamic routing are specified on the Dynamic Routing view on the Properties tab. Here is a single parameter (Service), any expressions configuring the routing should be defined here.

Once the link, placed against the Service parameter, is clicked, a window to edit these expressions appears. The windows consists of four zones:

  • Expression - routing configuration is based upon string literals or XQuery expressions. This kind of configuration looks like the Assign action in BPEL.
  • XQuery Resources - routing configuration is based upon a file which contains some XQuerty mapping.
  • XSLT Resources - routing configuration is based upon a file which contains some XSLT mapping.
  • Dynamic XQuery - routing configuration is based upon dynamic XQuery expressions and expression-to-parameters bindings.

Since the dynamic routing rule in use is trivial, the path to the business service is the concatenation of the CountryRouter/BusinessServices/BusinessService string literal and the value assigned to the country tag in request, the Expression tab is the right place for the configuration.

The expression is wrapped by some XML code, the code consists of the service (the path to the business service) element as well as operation (the name of the interesting operation, is actual if the business service is WSDL-based). The service element contains the isProxy attribute, the attribute value should be specified to true if the target is a proxy service.

The text inside the Expression tab is a string literal. Any XQuery expressions must be wrapped by braces ({}).

The routing rule for the project is shown bellow:


When the proxy service as well as the required business services and routing rules have been deployed to an OSB server, the proxy service may be tested. The OSB Console is used for these purposes. All projects deployed on the OSB server are displayed on Project Explorer.

In order to test a proxy service, the ProxyServices folder of the CountryRouter project has to be opened. The following list of available proxy services will appear.

Here is the Launch Test Console button. Once the button is pressed, the Proxy Service Testing window appears. The required values of the SOAP Header and Payload parameters should be assigned to the appropriate fields.

Let's assign Eng as the content of the country tag and press the Execute button. Once the request is processed, the following window appears:

The request has been processed successfully and the result equals to ENG.

Enterprise Manager shows a new instance of the SomeServiceEng service was created.

Now let's assign Ru to the contry tag and press the Execute button.

The result is equal to RU.

Enterprise Manager shows a new instance of the SomeServiceRu was created.

If a wrong value is assigned to the country tag, e.g. Fr, the following error will be generated: Error preparing message for dispatch.

One thing more. The SomeServiceEng and SomeServiceRu are invoked correctly, they accept the messages defined by the WSDL for the proxy service, not by the WSDL definition of the servives themselves; that is, the root tag of messages is sendMessage and the country parameter is assigned to the country tag instead of the message tag and the country attribute respectively. The messages will be processed successfull until someone touches the country attribute inside the services. The mapping to the correct format should be added to the message flow of the CountryProxyService service. But this is a topic of another article.

Would you like to give a 'Like'? Please follow me on Twitter!

No comments:

Post a Comment