全部博文(389)
分类: Oracle
2016-04-09 03:50:40
配置Goldengate向JMS(ActiveMQ)发布消息
通过Goldengate的Application Adpater可以方便的向JMS队列发送消息,其他应用程序通过订阅JMS消息
来对数据作一步处理或是操作.
环境:
jdk 1.7(安装目录/usr/local/jdk17)
ogg:11.2.1
os:redhat 5.5
ActiveMQ: 5.8(安装目录/usr/local/amq/apache-activemq-5.8.0)
假设现在安装好了Goldengate,安装目录为/u01/app/ogg,源端的extract和datapump的相关配置
可以直接参考官方文档,本文不再写出相关过程.
Goldengate既可以直接通过源端的datapump进程来发送jms消息;也可以通过远端接收trail文件,
然后在远端再配置extract来捕捉trail文件中的内容,然后再向jms服务器发布消息,这种配置的好处
可以减少直接在源端服务器上操作,而且源端服务器上不需要安装数据库软件,本例采用的是后一
种方案.
下载Application Adpater包,并且解压,复制libggjava_ue.so,libggjava_vam.so和ggjava文件
夹到Goldengate的安装目录下
[oracle@localhost ogg]$pwd
/u01/app/ogg
[oracle@localhost ogg]$ ls -l | grep ggjava
drwxr-xr-x 5 oracle oinstall 4096 Apr 8 23:27 ggjava
-rw-r--r-- 1 oracle oinstall 9390 Apr 8 21:45 ggjava.jar
-rwxr-xr-x 1 oracle oinstall 244273 Apr 8 21:46 libggjava_ue.so
-rwxr-xr-x 1 oracle oinstall 319030 Apr 8 21:46 libggjava_vam.so
定义正确的PATH,LD_LIBRARY_PATH和CLASSPATH
export LD_LIBRARY_PATH=/usr/local/jdk17/jre/lib/amd64:/usr/local/jdk17/jre/lib/amd64/server:$LD_LIBRARY_PATH
export CLASSPATH=$CLASSPATH:/usr/local/amq/apache-activemq-5.8.0
在远端的服务器上的ogg安装目录dirprm中增加一个javaue.properties
### javaue.properties (GoldenGate Java Extract properties file)
gg.handlerlist=myjms1
gg.classpath=/u01/app/ogg/ggjava/activemq-all-5.8.0.jar (从ActiveMQ安装目录复制)
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://192.168.23.51:61616
gg.handler.myjms1.type=jms
gg.handler.myjms1.destination=dynamicQueues/bv
gg.handler.myjms1.connectionFactory=ConnectionFactory
gg.handler.myjms1.format=xml
### native library config ###
goldengate.userexit.nochkpt=TRUE
goldengate.userexit.timestamp=utc
goldengate.log.logname=cuserexit
goldengate.log.level=INFO
goldengate.log.tofile=true
goldengate.userexit.writers=javawriter
#javawriter.stats.time=3600
#javawriter.stats.numrecs=10000
javawriter.stats.full=TRUE
javawriter.stats.display=TRUE
javawriter.bootoptions=-Xmx32m -Xms32m -Djava.class.path=/u01/app/ogg/ggjava/ggjava.jar:/u01/app/ogg/dirprm:/usr/local/amq/apache-activemq-5.8.0:/usr/local/amq/apache-activemq-5.8.0/activemq-all-5.5.0.jar:/usr/local/amq/apache-activemq-5.8.0/lib/optional/log4j-1.2.14.jar:/usr/local/amq/apache-activemq-5.8.0/lib/optional/slf4j-log4j12-1.5.11.jar -Dlog4j.configuration=log4j.properties
在远端的ogg中增加一个extract进程
GGSCI (localhost.localdomain) 1> edit param javaue
EXTRACT javaue
setEnv ( GGS_USEREXIT_CONF = "dirprm/javaue.properties" )
GetEnv (JAVA_HOME)
GetEnv (PATH)
GetEnv (LD_LIBRARY_PATH)
GetEnv (LIBPATH)
CUserExit libggjava_ue.so CUSEREXIT PASSTHRU INCLUDEUPDATEBEFORES
sourceDefs ./dirdef/t1.def
getUpdateBefores
TABLE frank.t1;
增加extract进程
GGSCI (localhost.localdomain) 4> add extract javaue, extrailsource ./dirdat/b1
启动extract进程,
GGSCI (localhost.localdomain) 5> start javaue
Sending START request to MANAGER ...
EXTRACT JAVAUE starting
Application Adpater的日志文件保存在ogg的目录中
[oracle@localhost ogg]$ ls -l cuserexit_20160409.log
-rw-rw-rw- 1 oracle oinstall 4286 Apr 9 03:38 cuserexit_20160409.log
GGSCI (localhost.localdomain) 4> info javaue
EXTRACT JAVAUE Last Started 2016-04-09 00:28 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:06 ago)
Log Read Checkpoint File ./dirdat/b1000000
First Record RBA 991731
016-04-09 00:28:27 INFO OGG-04525 Oracle GoldenGate Capture for Oracle, javaue.prm: /u01/app/ogg/extract running with user exit library libggjava_ue.so, current session character set is UTF-8.
2016-04-09 00:28:33 INFO OGG-00993 Oracle GoldenGate Capture for Oracle, javaue.prm: EXTRACT JAVAUE started.
可以看到已经成功加载libggjava_ue.so
在源端insert一条数据,然后测试一下
DONGDONGTANG >insert into frank.t1 values(15);
1 row created.
DONGDONGTANG >commit;
Commit complete.
打开jms服务器,我们已经发现这条记录已经被成功发送到gg.handler.myjms1.destination中定义的队列上了
Message Details