Oracle GoldenGate Java Adaptor的安装与配置

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

目录
Java Adapter的安装与配置 (2)
1.1在Weblogic上创建JMS Queue (2)
1.2生成JMS客户端 (6)
1.3GoldenGate配置过程 (6)
1.3.1安装JDK (6)
1.3.2安装GG for Java (6)
1.3.3配置Extract (7)
1.3.4生成Source Def配置文件 (8)
1.3.5配置Data Pump (8)
1.4测试 (15)
1.5Java测试客户端样例 (17)
1.5.1JMSSender.java (17)
1.5.2JMSReceiver.java (20)
Java Adapter的安装与配置
GoldenGate提供Java Adapter可以将复制目标端设置为JMS队列,将源数据库表记录内容,按照既定的转换规则,发布到JMS队列,以满足客户灵活的要求,具体实现方法如下文所述。

1.1 在Weblogic上创建JMS Queue
配置方法参见Weblogic相关资料,简要步骤如下:
1、配置消息存储(Message Stores)
Services->Persistent Stores,New->Create FileStore
输入文件存储的名字和目录,这个目录很重要,开始我以为是本地的一个目录就行了,其实测试之后发现必须是建立的domain下的一个目录才行,把目录名写上去就ok了。

例如:C:\Oracle\Middleware\user_projects\domains\osb_domain\ODIFileStore
目录名:ODIFileStore,不用写全路径
2、配置JMS Server
Services -> Messaging -> JMS Server -> Select New
Create a name, select Persistent Store (选择上面建立的消息存储:ODIFileStore) Target this to the AdminServer
3、配置连接工厂(Connection Factories)。

Services -> Messaging -> JMS Module -> jmsResources -> Connection Factory 建立子部署Create a new Subdeployment,默认名称即可ODIConnectionFactory
4、配置消息目的地(Destinations)
Queue或者Topic,本文使用Queue
Services -> Messaging -> JMS Module -> jmsResources-> Queue
名称:ODIQueue
管理子部署到上面的连接工厂ODIConnectionFactory,这里会报错,重启后再指定即可。

也可以建立新的子部署。

1.2 生成JMS客户端
创建JMS 客户端必须使用低版本的Weblogic,使用最新的Weblogic 11g的版本,生成的客户端,在运行过程中会报错:“找不到Class:weblogic/security/subject/AbstractSub ject”,因为最新的版本的Weblogic.jar里面已经不包含该类。

本文使用Weblogic10.3的版本生成JMS 客户端。

生成的JMS 客户端是供GG使用,和目标JMS Queue所在的Weblogic版本无关,目标Weblogic的版本可以使用最新的11g 的版本,本文使用的是11gr1(10.3.3)版本。

进入Weblogic10.3的安装目录:WL_HOME/server/lib,执行如下命令:
java -jar wljarbuilder.jar -profile wlfullclient5
将生成的wlfullcient5.jar拷贝到ODI目录下的driver目录即可。

该客户端是供JDK1.5版本使用,而GoldenGate要求是JDK1.6版本,本文测试通过,没有问题。

保险起见,生成JDK1.6版本的JMS客户端
java -jar wljarbuilder.jar
在GoldenGate安装目录,新建dirlib目录,将生成的jar文件拷贝到dirlib目录
1.3 GoldenGate配置过程
1.3.1 安装JDK
安装JDK1.6版本
在系统变量里面设置JAVA_HOME和PATH环境变量:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0
set PATH=%JAVA_HOME%\bin;%PATH%
set PATH=%JAVA_HOME%\jre\bin\server;%PATH%
1.3.2 安装GG for Java
将安装包解压到GG安装目录,解压后目录结构如下:
1.3.3 配置Extract
和GG正常配置一样,下面供参考:
GGSCI > DBLOGIN USERID system, PASSWORD oracle
Successfully logged into database.
GGSCI> ADD TRANDATA gg_src.TCUSTMER
Logging of supplemental redo data enabled for table GG_SRC.TCUSTMER.
GGSCI> ADD EXTRACT EXTMQ, TRANLOG, BEGIN NOW, THREADS 1
EXTRACT added.
GGSCI> EDIT PARAM EXTMQ
EXTRACT EXTMQ
USERID gg_src, PASSWORD gg_src
EXTTRAIL ./dirdat/mq/mq
TABLE gg_src.TCUSTMER;
GGSCI> ADD EXTTRAIL ./dirdat/mq/mq, EXTRACT EXTMQ,MEGABYTES 5 EXTTRAIL added.
GGSCI > START EXTMQ
Sending START request to MANAGER ('GGS') ...
EXTRACT EXTMQ starting
GGSCI> INFO ALL
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EXTMQ 00:00:03 00:00:01
1.3.4 生成Source Def配置文件
编辑参数文件source.prm,放在dirprm目录下:
DEFSFILE ./dirdef/source.def, PURGE
--SOURCEDB orcl, USERID gg_src, PASSWORD gg_src
USERID gg_src, PASSWORD gg_src
TABLE GG_SRC.TCUSTMER ;
进入GG安装目录,执行如下命令:
defgen paramfile ./dirprm/source.prm reportfile ./dirrpt/source.rpt
1.3.5 配置Data Pump
在dirprm目录下,编辑如下属性文件:
javaue.prm
javaue.properties
weblogic.properties:从安装包javaue\docs\sample-dirprm\jms拷贝,按照前面JMSQueue配置信息修改即可。

javaue.prm:
-- (1) before starting mgr, be sure the JVM is in the library path
-- sh> echo $LD_LIBRARY_PATH
-- ggsci> start mgr
--
-- (2) add a data-pump extract, reading a trail, to load/run the user-exit:
-- ggsci> delete extract javaue
-- ggsci> add extract javaue, extTrailSource dirdat/tk --
-- ggsci> start javaue -- ggsci> info javaue
Extract javaue
SourceDefs dirdef/source.def
-- 下面这两个环境变量文档描述是可选设置
-- 经测试必须设置经测试必须设置,,否则Data Pump 启动报错启动报错,,可设置成一个属性文件 SETENV (GGS_USEREXIT_CONF = "dirprm/javaue.properties") -- SETENV (GGS_USEREXIT_CONF = "dirprm/cuserexit.properties") SETENV (GGS_JAVAUSEREXIT_CONF = "dirprm/javaue.properties")
-- output to report file the path to libjvm.so / jvm.dll. On Linux/Solaris
-- use LD_LIBRARY_PATH, on Windows uses PATH, on AIX and z/OS use LIBPATH...
GetEnv (JAVA_HOME) GetEnv (PATH)
GetEnv (LD_LIBRARY_PATH)
-- CUserExit JavaUserExit.so CUSEREXIT PassThru IncludeUpdateBefores CUSEREXIT
JavaUserExit.dll
CUSEREXIT
PASSTHRU
INCLUDEUPDATEBEFORES
-- Only data that's already in the trail gets passed to the user-exit, -- but, DO include all data from trail. Filtering data passed to the user-exit -- risks missing begin/end tx markers.
GetUpdateBefores
NoCompressDeletes
NoCompressUpdates
NoT cpSourceTimer
ReportCount Every 1000 Records, Rate
-- include all data from trail. Don't filter data passed to the user-exit, or else
-- might miss transaction boundaries on records (tx markers for begin/middle/end) Table GG_SRC.*;
javaue.properties:
# list of active handlers
gg.handlerlist=myjms
gg.classpath=dirlib/wlfullclient.jar
gg.handler.myjms.type=jms
gg.handler.myjms.destination=ODIQueue
gg.handler.myjms.format=xml
gg.handler.myjms.queueortopic=queue
gg.handler.myjms.properties=weblogic.properties
#####################################################
#gg.handler.myjms.type=singlefile
#gg.handler.myjms.format=op.vm
#gg.handler.myjms.file=output-vm-op.xml
#####################################################
############################################################### # C-Side LOG Settings
# Set to DEBUG at the module level for trace message
# Keep at info for informational messages
goldengate.log.modules=UEUTIL,GENUSEREXIT,LOGMALLOC,TXSTORE,UTILS ,DSUSEREXIT,JAVAWRITER
goldengate.log.level=DEBUG
#goldengate.log.level=INFO
#goldengate.log.level.UEUTIL=INFO
goldengate.log.level.JAVAUSEREXIT=DEBUG
#goldengate.log.level.TXBUF=DEBUG
#goldengate.log.level.DUPCHK=DEBUG
goldengate.log.level.JAVAWRITER=DEBUG
goldengate.log.level.LOGMALLOC=ERROR
goldengate.log.logname=javauserexit_c
goldengate.log.tostdout=false
goldengate.log.tofile=true
# duplicates-checkpoint-file prefix. Set nochkpt=TRUE to *disable*.
erexit.chkptprefix=JAVAUE_
erexit.nochkpt=TRUE
# for tx timestamp, use datatbase local (default) or UTC timestamp
erexit.timestamp=utc
# prefix for logfile name
goldengate.log.logname=cuserexit
############################################################### # set "transaction" or "operation" mode (if in ops mode, set buffertxs=false)
erexit.outputmode=txs
#erexit.outputmode=ops
#erexit.buffertxs=FALSE
############################################################### erexit.writers=javawriter
# stats, minimum number of {records, seconds} before generating a report
javawriter.stats.time=3600
javawriter.stats.numrecs=1000
javawriter.stats.display=TRUE
javawriter.stats.full=TRUE
############################################################### # Initialize the JVM
# * Use ':' separators for Unix, ';' for windows.
# * Set the log4j configuration
# See the example preconfigured log4j files in resources/classes;
# if modifying, copy to dirprm, rename, then customize as desired.
###############################################################
#javawriter.bootoptions=-Xmx48m -Xms48m -Djava.class.path=dirprm:ggjava/ggjava.jar -Dlog4j.configuration=log4j.properties javawriter.bootoptions=-Djava.class.path=javaue/ggue.jar
-Dlog4j.configuration=log4j.properties -Xmx128m
weblogic.properties:
# ====================================================
# JMS Configuration for WebLogic Server
# ====================================================
gg.jmshandler.persistent=false
gg.jmshandler.durabletopic=false
# auto: Session.AUTO_ACKNOWLEDGE;
# client: Session.CLIENT_ACKNOWLEDGE;
# dupsok: Session.DUPS_OK_ACKNOWLEDGE;
gg.jmshandler.sessionmode=auto
# if using queue
gg.jmshandler.queueortopic=queue
# gg.jmshandler.destination=weblogic.examples.jms.exampleQueue
gg.jmshandler.destination=ODIQueue
# if using topic
# gg.jmshandler.queueortopic=topic
# gg.jmshandler.destination=topic.A
# if authentication is required
er=weblogic
gg.jmshandler.password=welcome1
# JNDI connection factory name to lookup
# eg, ./wlserver_10.0/samples/domains/wl_server/config/jms/examples-jms.xml
# <jndi-name>weblogic.examples.jms.QueueConnectionFactory</jndi-name>
# gg.jmshandler.connectionfactory=weblogic.examples.jms.QueueConnectionFactory gg.jmshandler.connectionfactory=ODIConnectionFactory
# if use JNDI (default=true), then lookup objects from IntialContext.
# Otherwise, provide classname to instantiate directly
# ejndi=false
# gg.jmshandler.connection.factoryclass=org.jboss.jms.client.JBossConnectionFactory
# ===============================================
# Standard JNDI properties for IntialContext
# ===============================================
# java.naming.factory.initial
# java.naming.factory.object
# java.naming.factory.state
# java.naming.factory.control
# java.naming.factory.url.pkgs
# java.naming.provider.url
# java.naming.dns.url
# java.naming.security.principal=my_jndi_username
# java.naming.security.credentials=my_jndi_password
java.naming.provider.url=t3://192.168.18.131:7001
java.naming.factory.url.pkgs=weblogic.jndi
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
GGSCI > ADD EXTRACT javaue, EXTTRAILSOURCE ./dirdat/mq/mq
EXTRACT added.
GGSCI > START JAVAUE
Sending START request to MANAGER ('GGS') ...
EXTRACT JAVAUE starting
GGSCI> INFO ALL
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EXTMQ 00:00:00 00:00:03
EXTRACT RUNNING JAVAUE 00:00:00 00:00:03
1.4 测试
在源数据库插入2条记录:
SQL> INSERT INTO tcustmer VALUES('A','ROCKY FLYER INC.','DENVER','CO');
1 row inserted
SQL> INSERT INTO tcustmer VALUES('B','ROCKY FLYER INC.','DENVER','CO');
1 row inserted
SQL> COMMIT;
Commit complete
在GoldenGate查看Report
GGSCI > SEND EXTRACT JAVAUE, REPORT
Sending REPORT request to EXTRACT JAVAUE ...
Request processed.
GGSCI > VIEW REPORT JAVAUE
可以看到报告最后显示的执行统计结果:
***********************************************************************
* ** Run Time Statistics ** *
***********************************************************************
Report at 2010-05-26 13:54:33 (activity since 2010-05-26 13:54:14)
From Table GG_SRC.TCUSTMER:
# inserts: 2
# updates: 0
# deletes: 0
# discards: 0
登录Weblogic console,进入JMS Queue,点击Show Message查看消息
点击其中的一条消息
查看结果如下:
可以看到表记录已经发送到JMS Queue,格式为javaue.properties属性文件里面设置的XML 格式。

javaue.properties:
gg.handler.myjms.format=xml
测试成功
可以编写JMS 接收客户端,将消息取出进行后续处理。

样例
1.5 Java测试客户端
测试客户端样例
创建java测试客户端,引入wljmsclient.jar和wljmxclient.jar,代码见下
1.5.1 JMSSender.java
package odi;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Hashtable;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
/**
* @author zhanping.liu
* @version 1.0
* @date 2010-05-15
* @class_displayName JMSSender
*/
public class JMSSender {
public void send() {
BufferedReader reader = new BufferedReader(new InputStreamReader( System.in));
String icf = "weblogic.jndi.WLInitialContextFactory";
String url = "t3://localhost:7001";
// Initialise JNDI properties
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, icf);
env.put(Context.PROVIDER_URL, url);
try {
// Lookup
final InitialContext initContext = new InitialContext(env);
QueueConnectionFactory factory = (QueueConnectionFactory) initContext .lookup("ODIConnectionFactory");
Queue destination = (Queue) initContext.lookup("ODIQueue"); initContext.close();
// Create JMS Object
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(destination);
// Send Message
String messageText = null;
while (true) {
System.out.println("Enter message to send or 'quit':");
messageText = reader.readLine();
if ("quit".equals(messageText))
break;
TextMessage message = session.createTextMessage(messageText);
sender.send(message);
}
// Exit
System.out.println("Exiting...");
reader.close();
connection.close();
System.out.println("Goodbye!");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("start test");
(new JMSSender()).send();
}
}
1.5.2 JMSReceiver.java package odi;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory; import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class JMSReceiver implements MessageListener {
private boolean stop = false;
public static void main(String[] args) {
(new JMSReceiver()).receive();
}
public void receive() {
String icf = "weblogic.jndi.WLInitialContextFactory";
String url = "t3://localhost:7001";
// Initialise JNDI properties
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, icf);
env.put(Context.PROVIDER_URL, url);
try {
// Look up administratered objects
final InitialContext initContext = new InitialContext(env);
QueueConnectionFactory factory = (QueueConnectionFactory) initContext
.lookup("ODIConnectionFactory");
Queue destination = (Queue) initContext.lookup("ODIQueue");
initContext.close();
// Create JMS objects
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = session.createReceiver(destination);
receiver.setMessageListener(this);
connection.start();
System.out.println("服务启动");
// Wait for stop
while (!stop) {
Thread.sleep(1000);
}
// Exit
System.out.println("Exiting...");
connection.close();
System.out.println("Goodbye!");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public void onMessage(Message message) {
try {
String msgText = ((TextMessage) message).getText();
System.out.println("接收到的消息是:" + msgText);
if ("stop".equals(msgText)) {
stop = true;
}
} catch (JMSException e) {
e.printStackTrace();
stop = true;
}
}
}。

相关文档
最新文档