This example shows how two application programs can take part in the same global transaction when using the same Resource Manager coordinated by the LIXA Transaction Manager. Please make sure that you are comfortable with previous sections and examples before setting this up.
The following relates to the figure above:
Application Program 1
: an application developed in C that is able to call functionality exposed by Application Program 2
Application Program 2
: an application developed in C that is able to fulfil service functionality when called by Application Program 1
A1 and B1
: includes Resource Manager specific calls during program execution
C1
: this is any custom protocol developed or used for communication between Application Program 1 and Application Program 2 - it is important to note that to make use of the Transaction Coupling extensions, one would have to share the XID between the programs.
This example was developed using the following configuration:
Oracle client and server with Oracle XE 11.2
GNU C compiler supplied with CentOS 7.3.1611:
[pieter.jvrensburg@centos-linux tmp]$ cc --version cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
The environment should be prepared following these steps:
The Oracle environment as explained in the section called “Oracle DMBS Configuration”. Please adapt to your version of Oracle installed.
Configuration of the Oracle listener for remote connections as explained in the section called “Configure Oracle Listener”.
Installation and configuration of the Oracle Instance Client (if required) as explained in the section called “Install and configure Oracle Instant Client”.
LIXA must be configured to support the Oracle Resource Manager as explained in the section called “Linking third party resource managers”.
Set up the required environment variables:
[Shell terminal session] |
[pieter.jvrensburg@centos-linux ~]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe [pieter.jvrensburg@centos-linux ~]$ export ORACLE_SID=XE [pieter.jvrensburg@centos-linux ~]$ export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh` [pieter.jvrensburg@centos-linux ~]$ export PATH=$ORACLE_HOME/bin:$PATH [pieter.jvrensburg@centos-linux ~]$ export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATHAnd for LIXA: [pieter.jvrensburg@centos-linux ~]$ export PATH=/opt/lixa/bin:/opt/lixa/sbin:$PATH [pieter.jvrensburg@centos-linux ~]$ export LD_LIBRARY_PATH=/opt/lixa/lib:$LD_LIBRARY_PATH |
Prepare the client (Application Program) using the below commands:
[Shell terminal session] |
[pieter.jvrensburg@centos-linux tmp]$ cp /opt/lixa/share/doc/lixa/X.Y.Z/examples/example15_transaction_coupling.c . [pieter.jvrensburg@centos-linux tmp]$ cc $(lixa-config -c -f -l) -L$ORACLE_HOME/lib -lclntsh -lnnz11 example15_transaction_coupling.c |
Next, verify the executable produced by cc:
[Shell terminal session] |
[pieter.jvrensburg@centos-linux tmp]$ ldd a.out linux-vdso.so.1 => (0x00007ffce4b13000) liblixac.so.0 => /opt/lixa/lib/liblixac.so.0 (0x00007f39938f6000) libclntsh.so.11.1 => /u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so.11.1 (0x00007f39910aa000) libnnz11.so => /u01/app/oracle/product/11.2.0/xe/lib/libnnz11.so (0x00007f3990ce2000) libc.so.6 => /lib64/libc.so.6 (0x00007f3990919000) libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f3990714000) libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f3990512000) libxml2.so.2 => /lib64/libxml2.so.2 (0x00007f39901a8000) liblixab.so.0 => /opt/lixa/lib/liblixab.so.0 (0x00007f398ff8a000) libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f398fc53000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f398fa37000) libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f398f831000) libm.so.6 => /lib64/libm.so.6 (0x00007f398f52f000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f398f32b000) libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f398f111000) libaio.so.1 => /lib64/libaio.so.1 (0x00007f398ef0f000) /lib64/ld-linux-x86-64.so.2 (0x00007f3993b17000) libz.so.1 => /lib64/libz.so.1 (0x00007f398ecf9000) liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f398ead2000) |
Set up the LIXA_PROFILE
environment variable:
[Shell terminal session] |
[pieter.jvrensburg@centos-linux ~]$ export LIXA_PROFILE=ORA_STA [pieter.jvrensburg@centos-linux ~]$ echo $LIXA_PROFILE ORA_STA |
See the section called “Some checks before program execution” for additional information on creating the profile configuration file.
This shows how a transaction was suspended and resumed within the same thread of control. The example in example15_transaction_coupling.c
does not interact with the actual Oracle database, but loads the switch file.
Make sure that the LIXA state server (lixad
) is
running before executing the example application, as explained in
the section called “Starting the state server (lixad)”.
The transaction is suspended, resumed and then rolled back:
[Shell terminal session] |
[pieter.jvrensburg@centos-linux tmp]$ LIXA_CONFIG_FILE=./lixac_conf.xml LIXA_PROFILE=ORA_STA ./a.out tx_open(): 0 tx_begin(): 0 tx_end(TMSUSPEND): 0 tx_info(): 1 tx_resume(): 0 tx_commit(): 0 tx_begin(): 0 tx_end(TMSUSPEND): 0 tx_info(): 1 tx_resume(): 0 tx_rollback(): 0 tx_close(): 0 |
This example shows a basic usage of the extended TX interface API calls. A more elaborate use case will include developing two application programs that communicate with each other and share the XID obtained from tx_info
so that the second application program can join the existing transaction.