Chapter 6. Using MRG Messaging with Java JMS
This chapter shows how to write direct, publish/subscribe, and request/response programs in Java JMS. These paradigms are explained in Chapter 2, Examples Overview. It then shows how to use important features like persistence and transactions with MRG Messaging. Unlike Python and C++, Java has an established API standard for messaging called JMS (Java Message Service). This chapter does not attempt to teach JMS programming. We suggest that you look at the Java JMS Tutorial for an extensive tutorial on JMS.
This chapter focuses on using Java JMS that can work together with AMQP clients written in other languages, even if these other clients use features not directly supported in Java JMS. In general, we accomplish this by using JNDI (Java Naming and Directory Interface) to specify properties for configuring queues and bindings.
The instructions in this section assume you have installed the client libraries and started a broker using the instructions shown in Chapter 3, Installing MRG Messaging.
The example code shown in this chapter is shipped as part of the rhm-docs package. Use rpm to see where this code is installed on your system:
$ rpm -qal rhm-docs
By default, these examples are placed in /usr/share/doc/rhm-0.2/java. There is a script in that directory that compiles and runs sample programs; it is called runSample.sh. This script takes the name of the class to be run as an argument, for example:
$ ./runSample.sh org.apache.qpid.example.jmsexample.direct.Producer
Run this script in a directory where you have write permission. You might need to copy the entire /usr/share/doc/rhm-0.2/java directory to a place where you can modify the code and create subdirectories as part of the compilation process. If you do not intend to modify the code, you can simply copy the script and run it from a directory where you have write privileges.