O'Reilly logo

Java EE 7 with GlassFish 4 Application Server by David R. Heffelfinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with message topics

Message topics are used when our JMS code uses the Publish/Subscribe (pub/sub) messaging domain. When using this messaging domain, the same message can be sent to all subscribers of a topic.

Sending messages to a message topic

Sending messages to a JMS topic is very similar to sending messages to a queue; simply inject the required resources and make some simple JMS API calls.

The following example illustrates how to send messages to a message topic:

package net.ensode.glassfishbook; import javax.annotation.Resource; import javax.jms.ConnectionFactory; import javax.jms.JMSContext; import javax.jms.JMSProducer; import javax.jms.Topic; public class MessageSender { @Resource(mappedName = "jms/GlassFishBookConnectionFactory") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required