/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package durabelesubscribers; import javax.naming.InitialContext; import javax.jms.Topic; import javax.jms.Session; import javax.jms.TopicSession; import javax.jms.TopicSubscriber; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; public class Subscribe { public static void main(String[] args) throws Exception { // get the initial context InitialContext ctx = new InitialContext(); // lookup the topic object Topic topic = (Topic) ctx.lookup("topic/topic0"); // lookup the topic connection factory TopicConnectionFactory connFactory = (TopicConnectionFactory) ctx. lookup("topic/connectionFactory"); // create a topic connection TopicConnection topicConn = connFactory.createTopicConnection(); topicConn.setClientID("durable"); // create a topic session TopicSession topicSession = topicConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); // create a topic subscriber TopicSubscriber topicSubscriber; topicSubscriber = topicSession.createDurableSubscriber(topic, "mySub"); System.out.println("created durable subscriber mySub"); // close the topic connection topicConn.close(); } }