Header Based Service Dispatching

Sample Number





This sample demonstrates header based dispatching using UltraESB

Use Case

I want to dispatch a service based on the header value.


Sample Configuration

In the following configuration, HttpNIOListener has been configured with HeaderBasedDispatcher. The two proxies "echo-proxy-1" and "echo-proxy-2" has the same transport url configured.

The decision of which service will be called is taken by looking at the header value. By default HeaderBasedDispatcher looks at the X-UE-ROUTING transport header.

 1 <bean id="http-8280" class="org.adroitlogic.ultraesb.transport.http.HttpNIOListener">
 2        <constructor-arg ref="fileCache"/>
 3        <property name="port" value="8280"/>
 4        <property name="dispatchManager">
 5            <bean class="org.adroitlogic.ultraesb.transport.dispatch.ServiceDispatchManager">
 6                <property name="dispatchers">
 7                    <list>
 8                        <bean class="org.adroitlogic.ultraesb.transport.http.util.HttpURLPatternBasedDispatcher"/>
 9                        <bean class="org.adroitlogic.ultraesb.transport.base.HeaderBasedDispatcher"/>
10                    </list>
11                </property>
12                <property name="dispatchingAggregated" value="true"/>
13            </bean>
14        </property>
15    </bean>
17    <u:proxy id="echo-proxy-1">
18        <u:transport id="http-8280">
19            <u:property name="ultra.transport.url" value="proxy"/>
20            <u:property name="ultra.transport.routing_header" value="test"/>
21        </u:transport>
22        <u:target>
23            <u:inDestination>
24                <u:address>http://localhost:9000/service/EchoService</u:address>
25            </u:inDestination>
26            <u:outSequence>
27                <u:java><![CDATA[
28                        System.out.println("Reply payload from test : " + mediation.readPayloadAsString(msg));
29                    ]]></u:java>
30            </u:outSequence>
31            <u:outDestination>
32                <u:address type="response"/>
33            </u:outDestination>
34        </u:target>
35    </u:proxy>
37    <u:proxy id="echo-proxy-2">
38        <u:transport id="http-8280">
39            <u:property name="ultra.transport.url" value="proxy"/>
40            <u:property name="ultra.transport.routing_header" value="prod"/>
41        </u:transport>
42        <u:target>
43            <u:inDestination>
44                <u:address>http://localhost:9000/service/EchoService</u:address>
45            </u:inDestination>
46            <u:outSequence>
47                <u:java><![CDATA[
48                        System.out.println("Reply payload from prod : " + mediation.readPayloadAsString(msg));
49                    ]]></u:java>
50            </u:outSequence>
51            <u:outDestination>
52                <u:address type="response"/>
53            </u:outDestination>
54        </u:target>
55    </u:proxy>

In Action

To run this sample, start the sample configuration number 118 from the command line as follows.

Running the sample from startup script

$ cd /opt/ultraesb-2.6.1/bin
$ ./ultraesb.sh -sample 118

Now start the SOA Toolbox, and fire-up the sample Jetty servers on port 9000 that holds sample echo service for testing. Now you have test echo service with service URL http://localhost:9001/service/EchoService. Then open a new HTTP/s client and set the url to http://localhost:8280/service/proxy. Go to the custom headers tab on the left and add "X-UE-ROUTING: test" or "X-UE-ROUTING: test". Please be careful about the custom header format otherwise it will be rejected by the toolbox. Now try sending any sample message. You can any of the preset messages as well.

What should happen is that according to the "X-UE-ROUTING" header value set, one of the two proxy services (echo-proxy-1 or echo-proxy-2) will be invoked. In the UltraESB log you will be able to see "Reply payload from test : " or "Reply payload from prod : " with the message payload according to the header you set.

In this topic
In this topic
Contact Us