码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-02-15 15:15:36      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:wso2

这篇文章介绍如何通过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


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

标签:wso2

原文地址:http://blog.csdn.net/szh1124/article/details/43834487

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!