Now that you are familiar with JMS behavior, let's look inside the application source files to examine some of the patterns that are used. You will see how you can make and compile some changes to the source files that expose FUSE Message Broker client's JMS features you can then test. (There are features that require setting broker configurations; those will be discussed in a forthcoming chapter.)
The application source files and the class files that they create are located
in application-specific folders that are subfolders of the two messaging models,
QueuePTPSamples, and
TopicPubSubSamples. The build file enabled you to enter
ant commands at the root of the samples such that ant chat1
did the same as navigating to the TopicPubSubSamples/Chat directory to run the
Chat.class file at that location as:
java Chat -u Chatter1The Chat folder contains the source
file Chat.java.
When you make changes to that or any other .java file, compile the source file to an updated class file and
then run the modified file. To do this, you need to have a Java Development Kit
(JDK) specified as JAVA_HOME, and the CLASSPATH
needs to specify the JDK's tools JAR, the FUSE Message Broker's activemq core JAR, and the
Geronimo JMS JAR. For example, on a Windows system, you might do the
following:
set JAVA_HOME=C:\jdk1.5.0_11
set FUSE_MB_=C:\progress\fuse-message-broker-5.3.0.0
set CLASSPATH=.;%JAVA_HOME%\lib\tools.jar; \
%FUSE_MB%\lib\activemq-core-5.3.0.0-fuse.jar; \
%FUSE_MB%\lib\geronimo-jms_1.1_spec-1.1.1.jar Then, with the command line located at the Chat directory, enter:
javac Chat.javaThe TopicPubSub samples show that the message is received by every subscriber
to the topic and its hierarchy -- including the publisher's connection. A
feature of JMS is the ability to set a noLocal Boolean on the
subscription that inhibits echoing messages sent in the publisher's connection.
In Chat.java you can set the noLocal value
to true but there is a catch: the method signature that sets
noLocal requires a message selector string also. On line
82 of Chat.java, the message consumer is listed as:
javax.jms.MessageConsumer subscriber = subSession.createConsumer(topic);
Edit the line to set the message selector to a zero-length String to satisfy
the method signature, and then add the boolean value true, as
follows:
javax.jms.MessageConsumer subscriber = subSession.createConsumer(topic, "", true);
When you save and compile this sample, see the effect in your samples. Start
chat1 and chat2. Send some messages
from each of the chatters. The messages are not echoed in that sender's
window.
Use the patterns in these sample applications to meld them and transform them from user interactive examples to applications that pass your data to the message producer, and that take messages received by message consumers to move them into your data stores and application logic. As always, provide proper copyrights and licenses in your source files and application packages.