Java Reference
In-Depth Information
Coding the Application Client: MultiAppServerClient.java
The application client class, multiclient/src/java/MultiAppServerCli-
ent.java , does the following.
1. It injects resources for two connection factories and a topic.
2. For each connection factory, it creates a connection, a publisher session, a publish-
er, a subscriber session, a subscriber, and a temporary topic for replies.
3. Each subscriber sets its message listener, ReplyListener , and starts the con-
nection.
4. Each publisher publishes five messages and creates a list of the messages the
listener should expect.
5. When each reply arrives, the message listener displays its contents and removes it
from the list of expected messages.
6. When all the messages have arrived, the client exits.
Coding the Message-Driven Bean: ReplyMsgBean.java
The message-driven bean class, replybean/src/ReplyMsgBean.java , does the
following:
1. Uses the @MessageDriven annotation:
@MessageDriven(mappedName ="jms/Topic")
2. Injects resources for the MessageDrivenContext and for a connection fact-
ory. It does not need a destination resource because it uses the value of the incom-
ing message's JMSReplyTo header as the destination.
3. Uses a @PostConstruct callback method to create the connection, and a
@PreDestroy callback method to close the connection.
The onMessage method of the message-driven bean class does the following:
1. Casts the incoming message to a TextMessage and displays the text
2. Creates a connection, a session, and a publisher for the reply message
3. Publishes the message to the reply topic
4. Closes the connection
On both servers, the bean will consume messages from the topic jms/Topic .
Search WWH ::




Custom Search