标签:
1. Place the jndi.properties file on the classpath.
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory # use the following property to configure the default connector java.naming.provider.url = vm://localhost # use the following property to specify the JNDI name the connection factory # should appear as. #connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry # register some queues in JNDI using the form # queue.[jndiName] = [physicalName] queue.MyQueue = example.MyQueue # register some topics in JNDI using the form # topic.[jndiName] = [physicalName] topic.MyTopic = example.MyTopic
2. Sample code
// create a new intial context, which loads from jndi.properties file javax.naming.Context ctx = new javax.naming.InitialContext(); // lookup the connection factory javax.jms.TopicConnectionFactory factory = (javax.jms.TopicConnectionFactory)ctx.lookup("ConnectionFactory"); // create a new TopicConnection for pub/sub messaging javax.jms.TopicConnection conn = factory.getTopicConnection(); // lookup an existing topic javax.jms.Topic mytopic = (javax.jms.Topic)ctx.lookup("MyTopic"); // create a new TopicSession for the client javax.jms.TopicSession session = conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE); // create a new subscriber to receive messages javax.jms.TopicSubscriber subscriber = session.createSubscriber(mytopic);
ActiveMQ(5.10.0) - JNDI Support
标签:
原文地址:http://www.cnblogs.com/huey/p/4748767.html