Sun GlassFish Message Queue 4.4 Developer's Guide for C Clients

Basic C-Client 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

Building the Basic C-Client Sample Programs

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.

To Compile and Link on Solaris OS


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:

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

To Compile and Link on Linux


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.

To Compile and Link on AIX


xlC_r -qthreaded -DAIX -I$IMQ_HOME/include -o Producer \\
    -blibsuff:so -l$IMQ_HOME/lib -imqcrt Producer.c

To Compile and Link on Windows


cl /c /MD -DWIN32 -I%IMQ_HOME%\include Producer.c

link Producer.obj /NODEFAULTLIB msvcrt.lib \\
      /LIBPATH:%IMQ_HOME%\lib mqcrt.lib

Running the Basic C-Client Sample Programs

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.