All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mq5.0-source.src.share.java.examples.jms20.asynctopicconsumer.README Maven / Gradle / Ivy


asynctopicconsumer example
--------------------------

Description
-----------
This example illustrates how to write an application that uses a
JMS2.0 simplified API to send messages and asynchronously receive messages  
to/from topic. It also illustrates the use of jdk7 feature try-with-resources in JMS application.

Some basic info on this example:

- SendMsgsToTopic.class sends messages to the particular topic specified and displays the messages sent.
- AsyncTopicConsumer.class receives messages asynchronously from the particular topic specified.
  Whenever a message has been sent to the topic, onMessage method is invoked on an
  MessageHandler object.
- Start AsyncTopicConsumer before starting the producer SendMsgsToTopic
  since a topic subscription will not receive messages which were sent to the topic before the subscription
  was created.

Files
-----
AsyncTopicConsumer.java           Source file for this example.
SendMsgsToTopic.java              Source file for this example.
*.class                 	  Prebuilt Java class files for this example.
README                            This file.

Configuring the environment
---------------------------
To recompile or run this example, you need to set CLASSPATH
to include at least:
    jms.jar
    imq.jar
    directory containing this example

A detailed guideline on configuring your environment and setting CLASSPATH
is found in the top-level README file of the examples (demo) directory of
the Message Queue installation (/examples/README) as well as in
the "Quick Start Tutorial" in the Oracle GlassFish(tm) Server Message Queue
Developer's Guide.

Building the example
--------------------
Run the following:

    javac AsyncTopicConsumer.java
    javac SendMsgsToTopic.java

Running the example
-------------------

Start a broker

   imqbrokerd -tty

Run the following command first on one terminal:

   java AsyncTopicConsumer  []

Run the following command on another terminal:

   java SendMsgsToTopic  []
  

The output of AsyncTopicConsumer looks like this:

java AsyncTopicConsumer topic1 5

Topic name is topic1
Created jms context successfully
Created topic successfully
Message Received : Message 1
Message Received : Message 2
Message Received : Message 3
Message Received : Message 4
Message Received : Message 5

The output of SendMsgsToTopic looks like this:

java SendMsgsToTopic topic1 5

Topic name is topic1
Created jms context successfully
Created topic successfully
Message sent : Message 1
Message sent : Message 2
Message sent : Message 3
Message sent : Message 4
Message sent : Message 5





© 2015 - 2024 Weber Informatics LLC | Privacy Policy