"OGG 02" Win7 Configuration Oracle GoldenGate Adapter Java Pit Guide

Source: Internet
Author: User

The previous article, "__win7 configuration ogg (Oracle GoldenGate). docx", set two goals:

    • Target 1:

Create two user admin and root for the installed oracle_11g.

Admin corresponds to the admin structure and creates a tb_ test table.

Root corresponds to the root structure and also creates a tb_ TEST (which is the same as the table structure).

When admin. when the table data in TB TEST changes, root. automatic synchronization of table data in TB TEST (Backup)

PS. Actual disaster recovery backup, must be two Oracle servers, transfer backup data over the network-you can imagine admin and Root on two different servers.

    • Target 2:

When admin. When the Tb_ TEST table data changes, this change is passed to Java and C # programs.

When a Java, C # program gets a data change message, it logs the changes to the log (or other operations).

Where goal 1 has been completed, we are starting to try Target 2

Download OGG Adapter Java:

Http://www.oracle.com/technetwork/cn/middleware/goldengate/downloads/index.html

To start configuring the Java Runtime Environment:
  • I began to regret that my system was 64-bit Win7.

  • I regret that I have installed 32-bit Oracle.

  • I regretted installing two sets of Jdk:c:\program files\java\jdk1.8.0121 and C:\Program Files (x86) \java\jdk1.8.0121.

  • I regretted that my Ogg catalogue took such a long name: D:\oracle\product\11.1.0\x86_ogg4oracle\

  • Next article: These pits will lead to a variety of strange problems-pits guide, the author with you in the pit together to fill in the failure to accumulate heavy experience, in the pits harvest absolute stability.

To configure environment variables:

My Computer 64-bit Win7, installed 64-bit, 32-bit two JDK. ORACLE_11G 32-bit, OGG 32-bit.

Do the following:

  • Found 64-bit JDK directory-right button, "360 Brute force Delete"-yes, brute force smash, which stems from my stepping on the pit of hatred, crushing, crushing. Desktop > Computer > Right-click > Properties > Advanced system Settings > Advanced tab > Environment variables.

CLASSPATH:.; %javaHome%\lib\tools.jar;%javahome%\lib\dt.jar;%java_home%\bin;

JAVAHome:c:\program Files (x86) \java\jdk1.8.0121

JREHome:c:\program Files (x86) \java\jre1.8.0121

Path:%java_home%\bin;

Verify Environment variables:

Open cmd (not detailed, CMD can not open, this article you do not have to read)

It is recommended to restart the computer, as if sometimes, Java environment variables to restart before the effective-restart to protect peace.

It's time to start testing Java Basics:

Open Eclipse and create a new Hello World project. Export the jar package.

Verify the Java Operating environment again:

What do you think this hello.jar is for? --Useless!

Do you know anything about metaphysics?

Install SQL Server You don't go to the toilet, you want to install it? "Toilet, reduce manual disk operation, SQL Server Setup is more stable"

You do not write a Hello word, you also want to put Ogg Adapter Java match? "is to validate the Java Runtime Environment, the Configurator's Java Foundation"

Start configuring OGG Adapter Java "Official code below, we want to verify the Ogg-java configuration environment First"

Look back: for ADMIN. Tb_test table-When data changes, our Java plug-in is able to capture data changes.

Generate a table structure definition file. "Goal: Get a. def suffix file (all other files in the process can be deleted)"

Create a text file in the D:\Temp\ folder SOURCE.PRM content as follows:

Run cmd to generate the Source.def file via SOURCE.PRM.

Locate the D:\oracle\product\11.1.0\x86ogg4oracletarget\ "target Side" double-click to run the Ggsci.exe program. Add Javaue

Configure Javaue

JAVAUE.PRM as follows:

Extract Javaue

Sourcedefs Dirprm/source.def

GETENV (Java_home)

--GETENV (LDLIBRARYPATH)

GETENV (PATH)

Cuserexit Ggjava_ue.dll cuserexit PassThru includeupdatebefores

Getupdatebefores

Table admin.*;

Javaue.properties as follows:

Gg.handlerlist=sample. Samplehandler

java.naming.provider.url=tcp://localhost:61616

Java.naming.factory.initial=org.apache.activemq.jndi.activemqinitialcontextfactory

Gg.handler.sample.type=sample. Samplehandler

Goldengate.userexit.timestamp=utc

Goldengate.userexit.nochkpt=true

Try to start Javaue

Ps.

If there is a "no error" error (the RPT file does not have any exception information), but the start Javaue window flashes over, the dead or alive cannot be started.

Remember the following: Starting Javaue with command-line parameter mode, you can display "no error" errors.

extract paramfile D:\oracle\product\11.1.0\x86_ogg4oracle_target\dirprm\javaue.prm

Formally write OGG Adapter Java plugin Code

New Project Custom, add jar package reference.

Create Java file Samplehandler, the source code is as follows:

Note: The code for OGG 12 and Ogg 11 is completely different.

---------------------------------------------------------------------------------------------------Package    Sample Package name sample, class name samplehandler--did it make you think of anything? Javaue.propertiesimport java.io.*;//This is the import import of OGG 11 Com.goldengate.atg.datasource.abstracthandler;import Com.goldengate.atg.datasource.dsconfiguration;import Com.goldengate.atg.datasource.dsevent;import Com.goldengate.atg.datasource.ggdatasource.status;import Com.goldengate.atg.datasource.meta.dsmetadata;import Com.goldengate.atg.datasource.test.dstestutils.logger;import Com.goldengate.atg.datasource.meta.*;import com.goldengate.atg.datasource.*;//This is OGG 12 's import//import Org.slf4j.logger;//import org.slf4j.loggerfactory;// Import Oracle.goldengate.datasource.abstracthandler;//import oracle.goldengate.datasource.dsconfiguration;// Import Oracle.goldengate.datasource.dsevent;//import Oracle.goldengate.datasource.dstransaction;//import Oracle.goldengate.datasource.conf.dshandler.handler.status;//import Oracle.goldeNgate.datasource.meta.dsmetadata;//import Oracle.goldengate.datasource.ggdatasource;public class SampleHandler    Extends Abstracthandler {//ogg 11 and Ogg 12 's logs seem different, and Ogg 12 seems to be writing loggerfactory.getlogger (Samplehandler.class); Private final Logger Logger = Com.goldengate.atg.datasource.test.DsTestUtils.Log4jLogger.getLogger (    Samplehandler.class);        @Override public void Init (dsconfiguration conf, Dsmetadata metaData) {super.init (conf, metaData);        Logger.info ("init!"); Writestringtofile ("D:\\samplehandler.    Log "," samplehandler.init (*) "); } @Override Public Status transactioncommit (dsevent E, Dstransaction tx) {logger.info ("transactioncommit!")        ; Writestringtofile ("D:\\samplehandler.         Log "," Samplehandler.transactioncommit (*) ");    return Status.ok;        } @Override public void Destroy () {Super.destroy (); Writestringtofile ("D:\\samplehandler.         Log "," Samplehandler.destroy (*) ");    Logger.info ("destroy!"); }   @Override public String Reportstatus () {writestringtofile ("D:\\samplehandler.         Log "," samplehandler.reportstatus (*) ");    return "Reportstatus";              } public void Writestringtofile (string filePath, string text) {try {System.out.println (text);              File File = new file (FilePath);              PrintStream PS = new PrintStream (new FileOutputStream (file));              Ps.println (text);//Writes a string ps.append (text) to a file;//Adds a string to an existing base} catch (FileNotFoundException e) {          E.printstacktrace (); }      }  }//---------------------------------------------------------------------------------------------------

Compile through, export the jar package:

Start Javaue again:

The window flashed again, failed to start, and went on to find the wrong one.

Ref: 49300853

Reinstall the Java environment, modify the 4 environment variables, and verify the Java installation environment.

java -jar D:\hello.jar

Restart your computer (or turn off all cmd, ggsci windows), reopen \x86ogg4oralcetarget\ggsci.exe input command: Start Mgr Start Javaue

Modern Poetry: "The Lost of Ogg"

That moment,

The tears are shining through the face,

I seem,

See the hope of success.

Wasted and struggled,

Tangled and bewildered.

In the toss, I can eventually go to the desired distance.

--Give me another chance, let me configure Ogg again.

--No! I choose to die (dozens) ~

Limerick: "The God pit ogg"

The most sacred pits are ogg,

The pit had no temper.

The pit has no temper.

The most ogg~ of God's Pit

To begin testing the success of the Javaue plugin:

The program crashes this time, comparing the two configurations:

In the following configuration (crash), we see a path of Dirlib/custom.jar.

We tried to copy the jar file exported from Eclipse D:\Temp\custom.jar to the \x86ogg4oracletarget\dirlib\ folder (dirlib to create manually)

Run again, or crash, or the same error message:

Although not an error, but why I insert, the plug-in code is not executed???

We delete the Javaue and then rebuild it:

Start start again javaue--remember my ID, no success, I live inverted write code ~

I was disappointed again: The plugin did not seem to execute-the plugin's code would generate a d:\ SampleHandler.log the log file, but the result is not.

I seem to have hit the face again--the pain ~

My whole people are not good, the days have been so difficult, really soon can not go on.

In my helpless, I have something to look at \x86ogg4oracletarget\ a few 6-letter folders.

Accidentally found a file that I was curious to open.

I saw a path: Yes! is the path to the data folder that I configured.

That's true! Do you have to verify the path? Although I eat the path of the loss on 5 times.

--but this path is true ah, still do not believe, I copied to you to see.

The whole person is not good, the biggest drawback of text configuration is: You knock hundreds of thousands of letters, a bit of hand can not be mistaken (the path is wrong and not prompted)

Rebuilding Javaue again, inserting data--I did not hold any hope this time, was tortured to cry, do not want to be beaten face.

I see a path: \dirdat\r1000000--feels strange:

Source-side Ext1 >>> target-side rep1, this data file has reached the r1000005-why Javaue still looking for r1000000

-Or, rebuild a ext2 at the source, use R2, and let Javaue find the data from R2?

Open source-side OGG directory: New ext2

Source side Add, start ext2, start success (I have been very familiar with):

Open the target side, rebuild Javaue, and use R2:

This time, we saw a code that didn't appear before:

Open the Dirdat directory:

Executing the Insert script again, the moment the data was inserted, Javaue crashed:

A face is crazy, the whole person is not good. Just when I was at a loss, I accidentally saw D:\. The SampleHandler.log file was created-although the program crashed, the Java code was executed.

Flagfile accidental configuration succeeded (not much in this article, just cut a picture)

Heart tired, and toss a day time. Let's just say the result:

OGG Adapter Java, only with/dirdat/r2000000 this data about "and version-independent, and x86 x64 independent, and source-side, target-side independent. 】

All the paths involved in the entire Ogg must use backslashes/. "If written D:\AAA\x86\ program may be recognized as garbled and bizarre crashes." 】

In particular note: When adding Javaue, the path must be inverted slash/

In fact, until now,

OGG Adapter Java x86 version crashes every time. Is the first two steps bug: Data changes captured, Java code executed, but the program crashed.

OGG Adapter Java version x64, I copied/DIRPRM/JAVAUE.PRM and/dirprm/javaue.properties and/dirprm/source.def three files from 11 to 12, performing the add Extract javaue--program can run normally, capturing data.

The OGG source must be consistent with the Oracle version and the 32\64 bit.

But OGG Adapter not so many restrictions. OGG Adapter only for Trail files such as/DIRDAT/R1 or/DIRDAT/R2.

The final scenario is as follows:

Look carefully at the lower right corner: I added an ogg x64--by this ogg to start the Javaue.

and Javaue only if the docking disk file dirdat\r2000001

Although there are two OGG x86, fortunately the disk trail file is interoperable.

To put a successful run:

I wrote a C # program to the ADMIN every second. Tb_test writes a row of records.

Theoretically ROOT. Tb_test will synchronize the data.

In theory Javaue can capture data changes.

At this point, the second goal is complete.

Finally, the final successful configuration is released:

Or see the next article, "OGG Adapter Java One-time success"

DIRPRM folder:

JAVAUE.PRM configuration:

Javaue.properties configuration:

Source.def is generated (generated by looking at the front of the article), Handwriting is invalid:

Custom.jar is the jar package exported after compilation:
---------------------------------------------------------------------------------------Package Sample;import Java.io.*;import Java.util.arraylist;import Java.util.list;import java.util.set;//This is the import of OGG 11//import Com.goldengate.atg.datasource.abstracthandler;//import Com.goldengate.atg.datasource.dsconfiguration;//import Com.goldengate.atg.datasource.dsevent;//import Com.goldengate.atg.datasource.ggdatasource.status;//import Com.goldengate.atg.datasource.handler.*;//import Com.goldengate.atg.datasource.meta.dsmetadata;//import Com.goldengate.atg.datasource.test.dstestutils.logger;//import Com.goldengate.atg.datasource.meta.*;//import com.goldengate.atg.datasource.*;//This is the import import org.slf4j.logger;import of OGG 12 Org.slf4j.loggerfactory;import Oracle.goldengate.datasource.abstracthandler;import Oracle.goldengate.datasource.dscolumn;import Oracle.goldengate.datasource.dsconfiguration;import Oracle.goldengate.datasource.dsevent;import Oracle.goldengate.datasource.dsoperation;iMport Oracle.goldengate.datasource.dsoperation.optype;import Oracle.goldengate.datasource.dstransaction;import Oracle.goldengate.datasource.ggtranid;import Oracle.goldengate.datasource.meta.columnmetadata;import Oracle.goldengate.datasource.meta.dsmetadata;import Oracle.goldengate.datasource.meta.tablemetadata;import Oracle.goldengate.datasource.meta.tablename;import Oracle.goldengate.datasource.ggdatasource.status;public Class Samplehandler extends Abstracthandler {//ogg 11 and Ogg 12 logs seem different, Ogg 12 seems to be writing Loggerfactory.getlogger (Samplehand    Ler.class);    Private final Logger Logger = Log4jlogger.getlogger (Samplehandler.class);    Private final Logger Logger = Loggerfactory.getlogger (Samplehandler.class);        @Override public void Init (dsconfiguration conf, Dsmetadata metaData) {super.init (conf, metaData);        Logger.info ("init!");    Writestringtofile ("D:\\samplehandler.log", "samplehandler.init (*)"); } @Override Public Status transactioncommit (DsevEnt e, Dstransaction tx) {//Dsmetadata meta = e.getmetadata ();////system.out.println (meta);///Set <TableName> tablenames = Meta.gettablenames ();//For (TableName tablename:tablenames) {//String table STR = "";//Tablestr = Tablestr + tablename+ ":";////tablemetadata metaData = Meta.gettablemetadata (ta  Blename);//arraylist<columnmetadata> columns = Metadata.getcolumnmetadata ();//For (Columnmetadata Column:columns) {//Tablestr = Tablestr + "\ r \ n" + column.getcolumnname () + "|"            +column.getdatatype (). toString ();//}////System.out.println (tablestr+ "\ r \ n");        System.out.println (metaData);//}//////ggtranid Tranid = E.gettargetcheckpointinfo ();// System.out.println (Tranid);///System.out.println (Tx.getsize ());//System.out.println (tx.gettotal Ops ());//System.out.println (TX. Getreadtime ());//System.out.println (Tx.gettransactionbegintime ());//////Object EventSource = e.ge      Teventsource ();//System.out.println (EventSource)///Dsoperation Lastop = Tx.getlastoperation ();// System.out.println (lastop);//////List<dsoperation> Listop = Tx.getoperations ();//System.out. println (Listop.size ());////system.out.println (Listop.get (0). GetColumn (0). Getbeforevalue ());//for (Dsoperation O P:listop) {//System.out.println (Op.gettablename ()),//} Status Superresult = Super.transactioncomm        It (E, TX);        Logger.info ("transactioncommit!");         Writestringtofile ("D:\\samplehandler.log", "samplehandler.transactioncommit (*) =" +superresult);    return superresult; } @Override Public Status operationadded (dsevent E, dstransaction tx, dsoperation dsoperation) {dsmetadata m        ETA = E.getmetadata (); SYSTEM.OUT.PRINTLN (meta);//Set<tablename> tablenames = Meta.gettablenames ();//For (TableName tablename:tablenames) {//String Tablestr = "" ;//Tablestr = Tablestr + tablename+ ":";////tablemetadata metaData = Meta.gettablemetadata (tableName) ;//arraylist<columnmetadata> columns = Metadata.getcolumnmetadata ();//For (columnmetadata column : columns) {//Tablestr = Tablestr + "\ r \ n" + column.getcolumnname () + "|"            +column.getdatatype (). toString ();//}////System.out.println (tablestr+ "\ r \ n");         System.out.println (metaData);//} System.out.println ("---------------------------------------");        OpType OpType = Dsoperation.getoperationtype ();        System.out.println (OpType);        TableName TableName = Dsoperation.gettablename ();        System.out.println (Tablename.getfullname ());        Tablemetadata metaData = Meta.gettablemetadata (tableName); Arraylist<columnmetadata> Columnmetas = Metadata.getcolumnmetadata ();        list<dscolumn> columns = Dsoperation.getcolumns ();            for (int i=0; i<columnmetas.size (); i++) {Columnmetadata Columnmeta = Columnmetas.get (i);            Dscolumn column = Columns.get (i); System.out.println ("" + columnmeta.getcolumnname () + "\ T | \ t "+ column.getaftervalue () + (column.ischanged ()?        "\ t >>> \ t" +column.getaftervalue (): ""));        } System.out.println ("---------------------------------------");        Status Superresult = super.operationadded (E, TX, dsoperation);        Logger.info ("operationadded!");         Writestringtofile ("D:\\samplehandler.log", "samplehandler.operationadded (*) =" +superresult);    return superresult;    }//@Override//public datasourcelistener.state getState () {//return super.getstate ();        } @Override public void Destroy () {Super.destroy (); Writestringtofile ("d:\\SampleHandler.log "," Samplehandler.destroy (*) ");    Logger.info ("destroy!");         @Override public String Reportstatus () {String superresult = "OK";//super.reportstatus (); Call the parent function and the program crashes.        Writestringtofile ("D:\\samplehandler.log", "samplehandler.reportstatus (*) =" +superresult);        return superresult;    Return "Status report...==="; public static void Writestringtofile (string filePath, string text) {try {System.out.pri             Ntln ("AAAAAAAAAAAAAAAAA:" + text);                 FileWriter writer = new FileWriter (FilePath, true);                   Writer.write ("\ r \ n" +text);             Writer.close ();              } catch (IOException e) {//e.printstacktrace ();         System.out.println (E.getmessage ()); }     }     }//---------------------------------------------------------------------------------------

At this point, the two main objectives of OGG complete. I almost stepped on the pits.

Although, I will write an article "OGG Adapter Java One-time success"

--but don't think too much: you still have to go back to this article and learn how to escape from the pit.

--This article of the Ogg trampled the pit, trample not less than more than 10 kinds of pits, from the configuration to the code, from the encoding format to the backslash, from the version in place, from the environment variable to the clerical error.

--The author is not easy.

End with a limerick: Modern Poetry: The Lost of Ogg

That moment,

The tears are shining through the face,

I seem,

See the hope of success.

Wasted and struggled,

Tangled and bewildered.

In the toss, I can eventually go to the desired distance.

--Give me another chance, let me configure Ogg again.

--No! I choose to die (dozens) ~

Limerick: "The God pit ogg"

The most sacred pits are ogg,

The pit had no temper.

The pit has no temper.

The most ogg~ of God's Pit

Two The poem gave OGG a meal, what else could it be? Of course, choose to forgive him.

Choux-Lone 2018-05-31 20:02

"OGG 02" Win7 Configuration Oracle GoldenGate Adapter Java Pit Guide

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.