You can run the clients using the appclient command. The build.xml file for each project includes a target that deploys the client and then retrieves the client stubs that the appclient command uses. Each of the clients takes one or more command-line arguments: a destination type and, for Producer, a number of messages.
To build, deploy, and run the Producer and SynchConsumer examples using Ant and the appclient command, follow these steps.
To run the clients, you need two terminal windows.
In a terminal window, go to the producer directory:
cd ../producer |
Deploy the client JAR file to the GlassFish Server, then retrieve the client stubs:
ant getclient |
Ignore the message that states that the application is deployed at a URL.
Run the Producer program, sending three messages to the queue:
appclient -client client-jar/producerClient.jar queue 3 |
The output of the program looks like this (along with some application client container output):
Destination type is queue Sending message: This is message 1 from producer Sending message: This is message 2 from producer Sending message: This is message 3 from producer |
The messages are now in the queue, waiting to be received.
When you run an application client, there is usually a noticeable delay between the first two application client container messages and the remainder of the output.
In the same window, go to the synchconsumer directory:
cd ../synchconsumer |
Deploy the client JAR file to the GlassFish Server, then retrieve the client stubs:
ant getclient |
Ignore the message that states that the application is deployed at a URL.
Run the SynchConsumer client, specifying the queue:
appclient -client client-jar/synchconsumerClient.jar queue |
The output of the client looks like this (along with some application client container output):
Destination type is queue Reading message: This is message 1 from producer Reading message: This is message 2 from producer Reading message: This is message 3 from producer |
Now try running the clients in the opposite order. Run the SynchConsumer client:
appclient -client client-jar/synchconsumerClient.jar queue |
The client displays the destination type and then appears to hang, waiting for messages.
In a different terminal window, run the Producer client.
cd tut-install/examples/jms/simple/producer appclient -client client-jar/producerClient.jar queue 3 |
When the messages have been sent, the SynchConsumer client receives them and exits.
Now run the Producer client using a topic instead of a queue:
appclient -client client-jar/producerClient.jar topic 3 |
The output of the client looks like this (along with some application client container output):
Destination type is topic Sending message: This is message 1 from producer Sending message: This is message 2 from producer Sending message: This is message 3 from producer |
Now run the SynchConsumer client using the topic:
appclient -client client-jar/synchconsumerClient.jar topic |
The result, however, is different. Because you are using a topic, messages that were sent before you started the consumer cannot be received. (See Publish/Subscribe Messaging Domain, for details.) Instead of receiving the messages, the client appears to hang.
Run the Producer client again.
Now the SynchConsumer client receives the messages (along with some application client container output):
Destination type is topic Reading message: This is message 1 from producer Reading message: This is message 2 from producer Reading message: This is message 3 from producer |