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 to the topic.
The following example illustrates how to send messages to a message topic:
package net.ensode.javaee8book.jmspubsubproducer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.JMSProducer;
import javax.jms.Topic;
@Named
@RequestScoped
public class MessageSender {
@Resource
private ConnectionFactory connectionFactory;
@Resource(mappedName = "jms/JavaEE8BookTopic")
private Topic topic;
private static final Logger LOG =
Logger.getLogger(MessageSender.class.getName());
public void produceMessages...