To run the sample programs using NetBeans IDE, follow these steps.
Run the Producer example:
Right-click the producer project and choose Properties.
Select Run from the Categories tree.
In the Arguments field, type the following:
queue 3 |
Click OK.
Right-click the project and choose Run.
The output of the program looks like this:
Destination type is queue Sending message: This is message 1 Sending message: This is message 2 Sending message: This is message 3 |
The messages are now in the queue, waiting to be received.
Now run the SynchConsumer example:
Right-click the synchconsumer project and choose Properties.
Select Run from the Categories tree.
In the Arguments field, type the following:
queue |
Click OK.
Right-click the project and choose Run.
The output of the program looks like this:
Destination type is queue Reading message: This is message 1 Reading message: This is message 2 Reading message: This is message 3 |
Now try running the programs in the opposite order. Right-click the synchconsumer project and choose Run.
The Output pane displays the destination type and then appears to hang, waiting for messages.
Right-click the producer project and choose Run.
The Output pane shows the output of both programs, in two different tabs.
Now run the Producer example using a topic instead of a queue.
Right-click the producer project and choose Properties.
Select Run from the Categories tree.
In the Arguments field, type the following:
topic 3 |
Click OK.
Right-click the project and choose Run.
The output of the program looks like this:
Destination type is topic Sending message: This is message 1 Sending message: This is message 2 Sending message: This is message 3 |
Now run the SynchConsumer example using the topic.
Right-click the synchconsumer project and choose Properties.
Select Run from the Categories tree.
In the Arguments field, type the following:
topic |
Click OK.
Right-click the project and choose Run.
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 program appears to hang.
Run the Producer example again. Right-click the producer project and choose Run.
Now the SynchConsumer example receives the messages:
Destination type is topic Reading message: This is message 1 Reading message: This is message 2 Reading message: This is message 3 |
You can also run the sample programs using the appclient command. Each of the programs takes one or more command-line arguments: a destination type and, for Producer, a number of messages.
To run the clients using the appclient command, follow these steps:
In a terminal window, go to the producer/dist directory:
cd ../producer/dist |
Run the Producer program, sending three messages to the queue:
appclient -client producer.jar queue 3 |
The output of the program looks like this:
Destination type is queue Sending message: This is message 1 Sending message: This is message 2 Sending message: This is message 3 |
The messages are now in the queue, waiting to be received.
In the same window, go to the synchconsumer/dist directory:
cd ../../synchconsumer/dist |
Run the SynchConsumer program, specifying the queue:
appclient -client synchconsumer.jar queue |
The output of the program looks like this:
Destination type is queue Reading message: This is message 1 Reading message: This is message 2 Reading message: This is message 3 |
Now try running the programs in the opposite order. Run the SynchConsumer program. It displays the destination type and then appears to hang, waiting for messages.
appclient -client synchconsumer.jar queue |
In a different terminal window, run the Producer program.
cd tut-install/javaeetutorial5/examples/jms/simple/producer/dist appclient -client producer.jar queue 3 |
When the messages have been sent, the SynchConsumer program receives them and exits.
Now run the Producer program using a topic instead of a queue:
appclient -client producer.jar topic 3 |
The output of the program looks like this:
Destination type is topic Sending message: This is message 1 Sending message: This is message 2 Sending message: This is message 3 |
Now run the SynchConsumer program using the topic:
appclient -client synchconsumer.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 program appears to hang.
Run the Producer program again. Now the SynchConsumer program receives the messages:
Destination type is topic Reading message: This is message 1 Reading message: This is message 2 Reading message: This is message 3 |
Because the examples use the common interfaces, you can run them using either a queue or a topic.