OpenAdaptor是Dresdner Kleinwort Wasserstein 开发的一款open source的产品,主要面向不同系统中的数据传递。 它可以很富方便地将一个系统中的数据输出(Source),经过一定的转化(Pipe),输出到其他系统(Sink)。
Source 数据获取对象,是一个接口,可以根据数据获取来源不同,实现很多子类,比如:FileSource、JMSSource等。它本身并没有定义任何方法,但是扩展了线程,所以它的核心方法应该就是线程的run方法。
Pipe 对source获取的数据进行处理,比如过滤、重新组织等,比如:FilterPipe。最上层是一个抽象类,核心方法是processMessage()
Sink 数据发布,将整合后的数据,根据配置文件,发布出去,比如:FileSink、JMSSink等。定义了一个接口,核心方法是processMessage()
Controller 整个消息传递的控制类,是一个线程,负责对上面所说的三个对象的调用,完成一次消息的传递,每一次消息的传递都会新建一个线程实例。定义了一个接口。
DataObject 传递消息数据的对象,定义了一个接口。
Message 对DataObject对象集合的封装,用来传递消息。
LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP。它是基于X.500标准的,但是简单多了并且可以根据需要定制。与X.500不同,LDAP支持TCP/IP,这对访问Internet是必须的。LDAP的核心规范在RFC中都有定义,所有与LDAP相关的RFC都可以在LDAPman RFC网页中找到。
详细简单说来,LDAP是一个得到关于人或者资源的集中、静态数据的快速方式、LDAP是一个用来发布目录信息到许多不同资源的协议。通常它都作为一个集中的地址本使用,不过根据组织者的需要,它可以做得更加强大。详细信息参照http://baike.baidu.com/view/159263.htm
下面是几个例子
eg1:csv to database
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: step07.xml 1285 2008-03-05 14:31:22Z higginse $
$HeadURL: https://openadaptor3.openadaptor.org/svn/openadaptor3/tags/3.4.5/example/tutorial/step07.xml $
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<description>
Adaptor for csv to database.
</description>
<bean id="Adaptor" class="org.openadaptor.core.adaptor.Adaptor">
<property name="messageProcessor" ref="Router"/>
</bean>
<bean id="Router" class="org.openadaptor.core.router.Router">
<property name="processMap">
<map>
<entry key-ref="ReaderA" value-ref="MapConverter"/>
<entry key-ref="MapConverter" value-ref="Writer"/>
</map>
</property>
</bean>
<bean id="ReaderA" class="org.openadaptor.auxil.connector.iostream.reader.FileReadConnector">
<property name="filename" value="input/inputA.csv" />
</bean>
<bean id="MapConverter" class="org.openadaptor.auxil.convertor.delimited.DelimitedStringToOrderedMapConvertor"> <description>将读取csv文件的数据转换成map类型;以下对应的行属性值,是和数据库中表trade1中相对应的。 以下三个属性name,number,text分别和数据库中的字段一致,且和下面的outputColumns的数值一致,反之,报错! </description>
<property name="fieldNames">
<list>
<value>SIDE</value>
<value>STOCK</value>
<value>PRICE</value>
</list>
</property>
</bean>
<bean id="JdbcConnection" class="org.openadaptor.auxil.connector.jdbc.JDBCConnection">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.121:1521:orcl"/>
<property name="username" value="ti1_user"/>
<property name="password" value="ti1_user"/>
</bean>
<bean id="Writer" class="org.openadaptor.auxil.connector.jdbc.writer.JDBCWriteConnector">
<property name="jdbcConnection" ref="JdbcConnection" />
<property name="writer">
<bean class="org.openadaptor.auxil.connector.jdbc.writer.map.MapTableWriter">
<property name="tableName" value="TRADE" />
<property name="outputColumns">
<description>以下对应的行属性值,是和数据库中表trade1中相对应的。以下三个属性name,number,text分别和数据库中的字段一致,且和上面的map的key值一致,反之,报错!
</description>
<list>
<value>SIDE</value>
<value>STOCK</value>
<value>PRICE</value>
</list>
</property>
</bean>
</property>
</bean>
</beans>
eg2:database to database
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: step09.xml 1508 2008-06-02 14:06:48Z cawthorng $
$HeadURL: https://openadaptor3.openadaptor.org/svn/openadaptor3/tags/3.4.5/example/tutorial/step09.xml $
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<description>
Adaptor for database1 to database2
</description>
<bean id="Adaptor" class="org.openadaptor.core.adaptor.Adaptor">
<property name="messageProcessor" ref="Router"/>
</bean>
<bean id="Router" class="org.openadaptor.core.router.Router">
<property name="processors">
<list>
<ref bean="readerConnector"/>
<ref bean="writerConnector"/>
</list>
</property>
</bean>
<bean id="sourceJdbcConnection" class="org.openadaptor.auxil.connector.jdbc.JDBCConnection">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.121:1521:orcl"/>
<property name="username" value="ti1_user"/>
<property name="password" value="ti1_user"/>
</bean>
<bean id="targetJdbcConnection" class="org.openadaptor.auxil.connector.jdbc.JDBCConnection">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.121:1521:orcl"/>
<property name="username" value="ti1_user"/>
<property name="password" value="ti1_user"/>
</bean>
<bean id="readerConnector" class="org.openadaptor.auxil.connector.jdbc.reader.JDBCReadConnector">
<description>Reader which polls database using configured SQL.</description>
<property name="jdbcConnection" ref="sourceJdbcConnection"/>
<property name="sql">
<value>
SELECT side as BUYSELL,stock as TICKER,price as PRICE
FROM TRADE
</value>
</property>
</bean>
<bean id="writerConnector" class="org.openadaptor.auxil.connector.jdbc.writer.JDBCWriteConnector">
<property name="jdbcConnection" ref="targetJdbcConnection" />
<property name="writer">
<bean class="org.openadaptor.auxil.connector.jdbc.writer.map.MapTableWriter">
<property name="tableName" value="TRADE2" />
</bean>
</property>
</bean>
<bean id="writer" class="org.openadaptor.auxil.connector.jdbc.writer.map.MapTableWriter">
<property name="tableName" value="trade2"/> <!-- -->
<property name="outputColumns">
<list>
<value>side</value><!--ݿֶ -->
<value>price</value>
<value>stock</value>
</list>
</property>
</bean>
<bean id="ExceptionHandler" class="org.openadaptor.auxil.connector.iostream.writer.FileWriteConnector"> <property name="filename" value="output/print.txt"/>
</bean>
</beans>
eg3:xml to csv
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: step07.xml 1285 2008-03-05 14:31:22Z higginse $
$HeadURL: https://openadaptor3.openadaptor.org/svn/openadaptor3/tags/3.4.5/example/tutorial/step07.xml $
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<description>
Adaptor for xml to csv
</description>
<bean id="Adaptor" class="org.openadaptor.core.adaptor.Adaptor">
<property name="messageProcessor" ref="Router">
</property>
</bean>
<bean id="Router" class="org.openadaptor.core.router.Router">
<property name="processors">
<list>
<ref bean="Reader"/>
<ref bean="XmlToMap"/>
<ref bean="FormatterScript"/>
<ref bean="maptostring"/>
<ref bean="Writer"/>
</list>
</property>
</bean>
<bean id="Reader" class="org.openadaptor.auxil.connector.iostream.reader.FileReadConnector">
<property name="filename" value="input/trades.xml"/>
<property name="dataReader">
<bean class="org.openadaptor.auxil.connector.iostream.reader.string.StringReader"/>
</property>
</bean>
<bean id="XmlToMap" class="org.openadaptor.auxil.convertor.xml.XmlToOrderedMapConvertor"/>
<bean id="maptostring" class="org.openadaptor.auxil.convertor.delimited.OrderedMapToDelimitedStringConvertor"/>
<bean id="FormatterScript" class="org.openadaptor.auxil.processor.script.ScriptProcessor">
<description>Convert Dom4j Document inton org.w3c.dom.Document</description>
<property name="script">
<value>
var trade=oa_data.get('Trade'); oa_data.put('SIDE',trade.get('buySell')); oa_data.put('STOCK',trade.get('ticker'));
oa_data.put('PRICE',trade.get('price'));
oa_data.remove('Trade'); //No longer needed
</value>
</property>
</bean>
<bean id="Writer" class="org.openadaptor.auxil.connector.iostream.writer.FileWriteConnector">
<property name="filename" value="output/dengjianli.csv"/>
</bean>
</beans>
eg4:xml to database
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: step07.xml 1285 2008-03-05 14:31:22Z higginse $
$HeadURL: https://openadaptor3.openadaptor.org/svn/openadaptor3/tags/3.4.5/example/tutorial/step07.xml $
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<description>
Adaptor for xml to database
</description>
<bean id="Adaptor" class="org.openadaptor.core.adaptor.Adaptor">
<property name="messageProcessor" ref="Router">
</property>
</bean>
<bean id="Router" class="org.openadaptor.core.router.Router">
<property name="processors">
<list>
<ref bean="Reader" />
<ref bean="xmltomap" />
<ref bean="FormatterScript" />
<ref bean="writer" />
</list>
</property>
</bean>
<bean id="Reader" class="org.openadaptor.auxil.connector.iostream.reader.FileReadConnector">
<description>Read entire contents of input file</description>
<property name="filename" value="input/trades.xml" />
<property name="dataReader">
<bean class="org.openadaptor.auxil.connector.iostream.reader.string.StringReader" />
</property>
</bean>
<bean id="xmltomap" class="org.openadaptor.auxil.convertor.xml.XmlToOrderedMapConvertor" />
<bean id="maptostring" class="org.openadaptor.auxil.convertor.delimited.OrderedMapToDelimitedStringConvertor" />
<bean id="FormatterScript" class="org.openadaptor.auxil.processor.script.ScriptProcessor">
<property name="script">
<value>
var trade=oa_data.get('Trade');
oa_data.put('SIDE',trade.get('buySell'));
oa_data.put('STOCK',trade.get('ticker'));
oa_data.put('PRICE',trade.get('price'));
oa_data.remove('Trade');
</value>
</property>
</bean>
<bean id="JdbcConnection" class="org.openadaptor.auxil.connector.jdbc.JDBCConnection">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.121:1521:orcl"/>
<property name="username" value="ti1_user"/>
<property name="password" value="ti1_user"/>
</bean>
<bean id="writer" class="org.openadaptor.auxil.connector.jdbc.writer.JDBCWriteConnector">
<property name="jdbcConnection" ref="JdbcConnection" />
<property name="writer">
<bean class="org.openadaptor.auxil.connector.jdbc.writer.map.MapTableWriter">
<property name="tableName" value="TRADE" />
</bean>
</property>
</bean>
</beans>
eg5:txt to database
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: step07.xml 1285 2008-03-05 14:31:22Z higginse $
$HeadURL: https://openadaptor3.openadaptor.org/svn/openadaptor3/tags/3.4.5/example/tutorial/step07.xml $
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<description>
Adaptor for xml to database
</description>
<bean id="Adaptor" class="org.openadaptor.core.adaptor.Adaptor">
<property name="messageProcessor" ref="Router">
</property>
</bean>
<bean id="Router" class="org.openadaptor.core.router.Router">
<property name="processors">
<list>
<ref bean="FileReader" />
<ref bean="writerConnector" />
</list>
</property>
<property name="exceptionProcessor" ref="ExceptionHandler" />
</bean>
<bean id="FileReader" class="org.openadaptor.core.node.ReadNode">
<property name="connector">
<ref bean="readerConnector" />
</property>
<property name="processor">
<ref bean="mapconverter" />
</property>
</bean>
<bean id="readerConnector" class="org.openadaptor.auxil.connector.iostream.reader.FileReadConnector">
<property name="filename" value="input/data.txt" />
<property name="dataReader">
<bean class="org.openadaptor.auxil.connector.iostream.reader.string.LineReader" />
</property>
</bean>
<bean id="mapconverter" class="org.openadaptor.auxil.convertor.delimited.DelimitedStringToOrderedMapConvertor"> <property name="delimiter" value="," />
<property name="fieldNames">
<list>
<value>SIDE</value>
<value>STOCK</value>
<value>PRICE</value>
</list>
</property>
</bean>
<bean id="targetJdbcConnection" class="org.openadaptor.auxil.connector.jdbc.JDBCConnection">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.121:1521:orcl"/>
<property name="username" value="ti1_user"/>
<property name="password" value="ti1_user"/>
</bean>
<bean id="writerConnector" class="org.openadaptor.auxil.connector.jdbc.writer.JDBCWriteConnector">
<property name="jdbcConnection" ref="targetJdbcConnection" />
<property name="writer">
<ref bean="writer" />
</property>
</bean>
<bean id="writer" class="org.openadaptor.auxil.connector.jdbc.writer.map.MapTableWriter">
<property name="tableName" value="TRADE1" />
</bean>
<bean id="ExceptionHandler" class="org.openadaptor.auxil.connector.iostream.writer.FileWriteConnector">
<property name="filename" value="output/puberror.txt" />
</bean>
</beans>
以上例子 都可以选择同一个用户 在同一个用户下创建3个结构相同的表 sql如下
create table TRADE
(
SIDE VARCHAR2(50),
STOCK VARCHAR2(50),
PRICE NUMBER(20)
)
tablespace TI_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
在运行以上实例的时候请参照如下目录下的 说明
D:\openadaptor-3.4.5-bin\openadaptor-3.4.5\example\tutorial\index.htm只需创建需要的xml文件并以 index.htm里面说的创建好环境后使用 java org.openadaptor.spring.SpringAdaptor -config step01.xml 在命令行模式下运行,注意以上都与队列无关,所以如果要使用队列的话,提供下面一个实例,
队列牵涉到发送端和接收端,所以需要配置两个xml文件,开两个cmd窗口运行,值得注意的是要在setclasspath.bat中添加一些需要的jar包,并且在运行前,在命令行下运行 setclasspath.bat文件,我的是这样的
set CLASSPATH=.
set CLASSPATH=%CLASSPATH%;..\..\lib\openadaptor.jar
set CLASSPATH=%CLASSPATH%;..\..\lib\openadaptor-spring.jar
set CLASSPATH=%CLASSPATH%;..\..\lib\openadaptor-depends.jar
set CLASSPATH=%CLASSPATH%;..\..\lib\3rdparty\hsqldb.jar
set CLASSPATH=%CLASSPATH%;..\..\lib\3rdparty\jbossall-client.jar
set CLASSPATH=%CLASSPATH%;..\..\lib\3rdparty\ojdbc14.jar
set CLASSPATH=%CLASSPATH%;..\..\lib\3rdparty\sqljdbc.jar
@echo on
使用两个xml文件从 database to database
,xml文件名自己取
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: step07.xml 1285 2008-03-05 14:31:22Z higginse $
$HeadURL: https://openadaptor3.openadaptor.org/svn/openadaptor3/tags/3.4.5/example/tutorial/step07.xml $
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<description>
Adaptor for step 7 of the tutorial.
</description>
<bean id="Adaptor" class="org.openadaptor.core.adaptor.Adaptor">
<property name="messageProcessor" ref="Router"/>
</bean>
<bean id="Router" class="org.openadaptor.core.router.Router">
<property name="processors">
<list>
<ref bean="Reader"/>
<ref bean="Writer"/>
</list>
</property>
</bean>
<bean id="JndiConnection" class="org.openadaptor.auxil.connector.jndi.JNDIConnection">
<property name="initialContextFactory" value="org.jnp.interfaces.NamingContextFactory"/>
<property name="providerUrl" value="jnp://localhost:1099"/>
</bean>
<bean id="JmsConnection" class="org.openadaptor.auxil.connector.jms.JMSConnection">
<property name="jndiConnection" ref="JndiConnection"/>
<property name="connectionFactoryName" value="ConnectionFactory"/>
</bean>
<bean id="JdbcConnection" class="org.openadaptor.auxil.connector.jdbc.JDBCConnection">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.121:1521:orcl"/>
<property name="username" value="ti1_user"/>
<property name="password" value="ti1_user"/>
</bean>
<!--<bean id="Reader" class="org.openadaptor.auxil.connector.jms.JMSReadConnector">
<property name="destinationName" value="queue/testQueue"/>
<property name="jmsConnection" ref="JmsConnection"/>
<property name="transacted" value="true"/>
</bean>-->
<bean id="Reader" class="org.openadaptor.auxil.connector.jdbc.reader.JDBCReadConnector">
<description>Reader which polls database using configured SQL.</description>
<property name="jdbcConnection" ref="JdbcConnection"/>
<!-- batch size of 0 or less means process all rows in one message batch. -->
<!-- batch size of one means process one row per message and so on -->
<property name="batchSize" value="0"/>
<property name="resultSetConverter">
<bean class="org.openadaptor.auxil.connector.jdbc.reader.xml.ResultSetToXMLConverter"/>
</property>
<property name="sql">
<value>
SELECT side as BUYSELL,stock as TICKER,price as PRICE
FROM TRADE
</value>
</property>
</bean>
<bean id="Writer" class="org.openadaptor.auxil.connector.jms.JMSWriteConnector">
<property name="destinationName" value="queue/testQueue"/>
<property name="jmsConnection" ref="JmsConnection"/>
</bean>
<!--<bean id="Writer" class="org.openadaptor.auxil.connector.iostream.writer.FileWriteConnector"/>-->
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: step09.xml 1508 2008-06-02 14:06:48Z cawthorng $
$HeadURL: https://openadaptor3.openadaptor.org/svn/openadaptor3/tags/3.4.5/example/tutorial/step09.xml $
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<description>
Adaptor for step 9 of the tutorial.
</description>
<bean id="Adaptor" class="org.openadaptor.core.adaptor.Adaptor">
<property name="messageProcessor" ref="Router"/>
</bean>
<bean id="Router" class="org.openadaptor.core.router.Router">
<property name="processors">
<list>
<ref bean="Reader"/>
<ref bean="XmlToMap"/>
<ref bean="FormatterScript"/>
<ref bean="Writer"/>
</list>
</property>
</bean>
<bean id="JndiConnection" class="org.openadaptor.auxil.connector.jndi.JNDIConnection">
<property name="initialContextFactory" value="org.jnp.interfaces.NamingContextFactory"/>
<property name="providerUrl" value="jnp://localhost:1099"/>
</bean>
<bean id="JmsConnection" class="org.openadaptor.auxil.connector.jms.JMSConnection">
<property name="jndiConnection" ref="JndiConnection"/>
<property name="connectionFactoryName" value="ConnectionFactory"/>
</bean>
<bean id="Reader" class="org.openadaptor.auxil.connector.jms.JMSReadConnector">
<property name="destinationName" value="queue/testQueue"/>
<property name="jmsConnection" ref="JmsConnection"/>
<property name="transacted" value="true"/>
</bean>
<bean id="XmlToMap" class="org.openadaptor.auxil.convertor.xml.XmlToOrderedMapConvertor"/>
<bean id="FormatterScript" class="org.openadaptor.auxil.processor.script.ScriptProcessor">
<property name="script">
<value>
<![CDATA[
var trade=oa_data.get('row');
oa_data.put('SIDE',trade.get('BUYSELL'));
oa_data.put('STOCK',trade.get('TICKER'));
oa_data.put('PRICE',trade.get('PRICE'));
oa_data.remove('row'); //No longer needed
]]>
</value>
</property>
</bean>
<bean id="JdbcConnection" class="org.openadaptor.auxil.connector.jdbc.JDBCConnection">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.1.121:1521:orcl"/>
<property name="username" value="ti2_user"/>
<property name="password" value="ti2_user"/>
</bean>
<bean id="Writer" class="org.openadaptor.auxil.connector.jdbc.writer.JDBCWriteConnector">
<property name="jdbcConnection" ref="JdbcConnection" />
<property name="writer">
<bean class="org.openadaptor.auxil.connector.jdbc.writer.map.MapTableWriter">
<property name="tableName" value="TRADE" />
</bean>
</property>
</bean>
</beans>
有问题欢迎讨论