Compiling the AsynchConsumer Client Example
Compiling the AsynchConsumer Client Example
The message listener, asynchconsumer/src/java/TextListener.java, follows these steps:
1. When a message arrives, the onMessage method is called automatically.
2. The onMessage method converts the incoming message to a TextMessage and displays its
content. If the message is not a text message, it reports this fact:
public void onMessage(Message message) {
TextMessage msg = null;
try {
if (message instanceof TextMessage) {
msg = (TextMessage) message;
System.out.println(
"Reading message: " + msg.getText());
} else {
System.out.println(
"Message is not a " + "TextMessage");
}
} catch (JMSException e) {
System.out.println(
"JMSException in onMessage(): " + e.toString());
} catch (Throwable t) {
System.out.println(
"Exception in onMessage():" + t.getMessage());
}
}
You will use the connection factory and destinations you created in
Compiling and Packaging the AsynchConsumer Client
To compile and package the AsynchConsumer example using NetBeans IDE, follow these steps:
1. In NetBeans IDE, choose Open Project from the File menu.
2. In the Open Project dialog, navigate to
tut-install/javaeetutorial5/examples/jms/simple/.
3. Select the asynchconsumer folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. Right-click the project and choose Build Project.
To compile and package the AsynchConsumer example using Ant, follow these steps:
1. In a terminal window, go to the asynchconsumer directory:
cd ../../asynchconsumer
2. Type the following command:
ant
Writing Simple JMS Client Applications
The Java EE 5 Tutorial · September 2007
922