This section describes the sample C-Client programs that are installed with Message Queue and explains how you should build them and run them.
Message Queue provides two sets of sample C-client programs: basic C-client programs and distributed transaction programs.
The sample C-client program files include the following:
Table 1–3 Basic C-Client Sample Program Files
Sample Program |
Description |
---|---|
Producer.c |
Illustrates how you send a message |
Consumer.c |
Illustrates how you receive a message synchronously |
ProducerAsyncConsumer.c |
Illustrates how you send a message and receive it asynchronously |
RequestReply.c |
Illustrates how you send and respond to a message that specifies a reply-to destination |
Table 1–4 lists the location of the sample programs for each installation method.
Table 1–4 Location of Basic C-Client Sample Programs
Installation Method |
Directory |
---|---|
IPS image |
IMQ_HOME/examples/C |
Solaris SVR4 packages |
/opt/SUNWimq/demo/C |
Linux rpm packages |
/opt/sun/mq/examples/C |
The following commands illustrate the process of building and linking the sample application Producer.c on the Solaris, Linux, AIX, and Windows platforms. The commands include the pre-processor definitions needed to support Message Queue C-API fixed-size integer types. For options used to support multithreading, please consult documentation for your compiler.
CC -compat=5 -mt -DSOLARIS -Iheader_path -o Producer \\ -Lruntime_path -lmqcrt Producer.c |
where header_path and runtime_path are the paths to the Message Queue header file and runtime shared library appropriate to your installation method and processor architecture, as listed in Table 1–1. For example, when using an installation from SVR4 packages on a Solaris x86 64–bit platform, you would specify /opt/SUNWimq/include as header_path and /opt/SUNWimq/lib/amd64 as runtime_path.
For 64-bit support on either the SPARC or x86 processor architecture, you must also specify the -xarch compiler option:
SPARC: -xarch=v9
x86: -xarch=amd64
For example, to compile and link the example application in an installation from SVR4 packages on Solaris SPARC 64–bit, you would use the following command:
CC -compat=5 -mt -xarch=v9 -DSOLARIS -I/opt/SUNWimq/include -o Producer \\ L/opt/SUNWimq/lib/sparcv9 -lmqcrt Producer.c |
g++ -DLINUX -D_REENTRANT -Iheader_path -o Producer \\ -Lruntime_path -lmqcrt Producer.c |
where header_path and runtime_path are the paths to the Message Queue header file and runtime shared library appropriate to your installation method, as listed in Table 1–1. For example, when using an installation from rpm packages, you would specify /opt/sun/mq/include as header_path and /opt/sun/mq/lib as runtime_path.
xlC_r -qthreaded -DAIX -I$IMQ_HOME/include -o Producer \\ -blibsuff:so -l$IMQ_HOME/lib -imqcrt Producer.c |
cl /c /MD -DWIN32 -I%IMQ_HOME%\include Producer.c link Producer.obj /NODEFAULTLIB msvcrt.lib \\ /LIBPATH:%IMQ_HOME%\lib mqcrt.lib |
Before you run any sample programs, you should start the broker. You can display output describing the command-line options for each program by starting the program with the -help option.
For example, the following command, runs the program Producer. It specifies that the program should connect to the broker running on the host MyHost and port 8585, and that it should send a message to the destination My Topic :
Producer -h MyHost -p 8585 -d MyTopic
The directories that contain the sample programs also include a README file that explains how you should run their respective samples.
The distributed transaction sample programs show how to use the X/Open distributed transaction (XA) support of the Message Queue C-API with an X/Open distributed transaction processing system (in this case BEA Tuxedo: http://edocs.bea.com/tuxedo/tux100/index.html.)
The distributed transaction sample programs include the following files:
Table 1–5 Distributed Transaction Sample Program Files
Sample Program |
Description |
---|---|
jmsserver.c |
Implements Tuxedo services that send and receive messages using the Message Queue C-API |
jmsclient_sender.c |
Tuxedo client that uses the message producing service in jmsserver.c |
jmsclient_receiver.c |
Tuxedo client that uses the message receiving service in jmsserver.c |
async_jmsserver.c |
Implements a Tuxedo service that asynchronously consumes messages using the Message Queue C-API |
jmsclient_async_receiver.c |
Tuxedo client that uses the asynchronous message consuming service in async_jmsserver.c |
Table 1–4 lists the location of the sample programs for each installation method.
Table 1–6 Location of Distributed Transaction Sample Programs
Installation Method |
Directory |
---|---|
IPS image |
IMQ_HOME/examples/C/tuxedo |
Solaris SVR4 packages |
/opt/SUNWimq/demo/C/tuxedo |
Linux rpm packages |
/opt/sun/mq/examples/C/tuxedo |
The following procedures document how to set up Tuxedo as a distributed transaction manager, how to build the sample distributed transaction programs, and how to run the sample programs. The procedures are based on the synchronous message consumption samples and assume a Solaris operating system platform.
Install Tuxedo.
See Tuxedo documentation for instructions.
Set up the following environment variables:
Environment Variable |
Description |
---|---|
LD_LIBRARY_PATH |
Modify to include Message Queue C-API runtime library path and TUXDIR/lib path |
TUXDIR |
Tuxedo install root |
PATH |
modify to include $TUXDIR/bin and compiler path |
TUXCONFIG |
TUXCONFIG filename path |
TLOGDEVICE |
Tuxedo transaction log filename path |
MQ_HOME |
Message Queue install root |
MQ_LOG_FILE |
Message Queue C-API runtime log file name |
MQ_LOG_FILE_APPEND_PID |
Set so that Message Queue C-API runtime log file name will be auto-appended with the Tuxedo server process id |
Build the Tuxedo transaction monitor server (TMS).
Configure the Tuxedo servers.
# tmloadcf config-file
where config-file is the Tuxedo UBBCONFIG file.
Build the server side of the sample application (jmsserver.c).
# cc -I$IMQ_HOME/include -I$TUXDIR/include -g -c jmsserver.c
# buildserver -v -t -r SUN_MQ -s SENDMESSAGES,RECVMESSAGES -o jmsserver -f jmsserver.o -f -lmqcrt
Build the client side of the sample application (jmsclient_sender.c and jmsclient_receiver.c).
# cc -I$TUXDIR/include -c jmsclient_sender.c # buildclient -o jmsclient_sender -f jmsclient_sender.o
# cc -I$TUXDIR/include -c jmsclient_receiver.c # buildclient -o jmsclient_receiver -f jmsclient_receiver.o
Start a Message Queue broker.
# imqbrokerd -tty
Start the Tuxedo servers.
# tmboot
Run the client-side applications.
# jmsclient_sender
# jmsclient_receiver
Confirm the messages are produced to and consumed from the applicable destination.
# imqcmd list dst -u admin
# imqcmd querry dst -t q -n xatestqueue -u admin