WSO2——(8)ESB功能:消息路由

这篇文章介绍如何通过WSO2 ESB实现消息路由的功能:基于内容的路由,根据消息内容的不同路由到不同的服务进行处理。

场景:投诉管理
描述:公众发起对律师或公证员的投诉,输入0转到律师服务进行处理,输入1转到公证员服务进行处理,其他值转到默认服务进行处理
3个服务:律师服务、公证员服务、默认服务

1 三个Axis2服务

默认服务Route:http://10.22.1.20:9763/services/Route?wsdl

package service.hello.ws.demo.com;

public class Route{
	public String litigate(String msg) {
		System.out.println("Route Test: " + msg + " coming! return 'Route: Hello "
				+ msg + "'");
		return "litigate Type " + msg;
	}
}

律师服务Lawyerhttp://10.22.1.20:9763/services/Lawyer?wsdl 

package service.hello.ws.demo.com;

public class Lawyer{
	public String litigate(String msg) {
		System.out.println("Lawyer: " + msg + " coming! return 'Lawyer Litigation "
				+ msg + "'");
		return "Lawyer Type "+msg;
	}
}

公证员服务Notary: http://10.22.1.20:9763/services/Notary?wsdl 

package service.hello.ws.demo.com;

public class Notary{
	public String litigate(String msg) {
		System.out.println("Notary: " + msg + " coming! return 'Notary Litigation "
				+ msg + "'");
		return "Notary Type" +msg;
	}
}

2 三个服务的三个端点

为上述三个服务分别建立端点。

3 一个代理服务RouteProxy

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="RouteProxy"
       transports="https,http"
       statistics="enable"
       trace="enable"
       startOnLoad="true">
   <target inSequence="routeInSequence" outSequence="routeOutSequence"/>
   <publishWSDL uri="http://10.22.1.20:9763/services/Route?wsdl"/>
   <description/>
</proxy>


3.1 routeInSequence

<pre name="code" class="html"><span style="font-weight: normal;"><?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse"
          name="routeInSequence"
          trace="enable"
          statistics="enable">
   <switch xmlns:ns="http://org.apache.synapse/xsd"
           xmlns:p="http://com.demo.ws.hello.service"
           source="$body//p:litigate/p:msg">
      <case regex="0">
         <property name="STATE" value="0" scope="default" type="STRING"/>
         <send>
            <endpoint key="RouteLawyerEndpoint"/>
         </send>
      </case>
      <case regex="1">
         <property name="STATE" value="1" scope="default" type="STRING"/>
         <send>
            <endpoint key="RouteNotaryEndpoint"/>
         </send>
      </case>
      <default>
         <send>
            <endpoint key="RouteEndpoint"/>
         </send>
      </default>
   </switch>
</sequence></span>


 3.2 routeOutSequence

<sequence xmlns="http://ws.apache.org/ns/synapse" name="routeOutSequence" trace="enable">
   <switch xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" source="get-property('STATE')">
      <case regex="0">
         <log level="full">
            <property name="Sequence" value="0"></property>
         </log>
         <send></send>
      </case>
      <case regex="1">
         <log level="full">
            <property name="Sequence" value="1"></property>
         </log>
         <send></send>
      </case>
      <default>
         <send></send>
      </default>
   </switch>
</sequence>

4 测试

输入0

输入1

输入其他值


具体参考 http://download.csdn.net/detail/szh1124/8447887


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值