This section describes the sample C-Client programs that are installed with Message Queue and explains how you should build them and run them. Table 1–3 lists the location of the sample programs on each platform.
Table 1–3 Location of C Sample Programs
Platform |
Directory |
---|---|
Solaris |
/opt/SUNWimq/demo/C |
Linux |
/opt/sun/mq/examples/C |
Windows |
IMQ_HOME\demo\C |
The following commands illustrate the process of building and linking the sample application Producer.c on the Solaris, Linux, and Windows platforms. The commands include the preprocessor definitions needed to support fixed-size integer types. For options used to support multithreading, please consult documentation for your compiler.
CC -compat=5 -mt -DSOLARIS -I/opt/SUNWimq/include -o Producer \\ -L/opt/SUNWimq/lib -lmqcrt Producer.c
For Solaris/SPARC, if you need 64-bit support, you need to specify the following compiler options: -xarch=v9 and -L/opt/SUNWimq/lib/sparcv9. For example, to compile and link the example application, 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 -I/opt/sun/mq/include -o Producer \\ -L/opt/sun/mq/lib -lmqcrt Producer.c
cl /c /MD -DWIN32 -I%IMQ_HOME%\include Producer.c
link Producer.obj /NODEFAULTLIB msvcrt.lib \\ /LIBPATH:%IMQ_HOME%\lib mqcrt.lib
The sample C client program files include the following:
Producer.c and Consumer.c, which illustrate how you send a message and receive it synchronously.
ProducerAsyncConsumer.c, which illustrates how you send a message and receive it asynchronously.
RequestReply.c, which illustrates how you send and respond to a message that specifies a reply-to destination.
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.
The directory that contains the sample programs also includes a README file that explains how you should run these samples. 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 :
C: Producer -h MyHost -p 8585 -d MyTopic