📄 topicmanager.java
字号:
package com.wls8unleashed.jms;
import javax.jms.*;
import javax.naming.*;
/**
* Provides common initialization work used for Topic
* subscribers and publishers.
*/
public class TopicManager {
protected TopicConnectionFactory topicConnectionFactory;
protected TopicConnection topicConnection;
protected TopicSession topicSession;
protected Topic topic;
/**
* Creates and initializes a bunch of topic resources.
*/
public TopicManager(Context context){
try{
// Get JMS factory JNDI name
String jmsFactoryName = Props.get("jms.factory.for.topic");
// Create topic connection factory
System.out.println("Looking up factory name: " + jmsFactoryName);
topicConnectionFactory =
(TopicConnectionFactory) context.lookup(jmsFactoryName);
// Create topic connection to the factory
System.out.println("Creating topic connection...");
topicConnection = topicConnectionFactory.createTopicConnection();
// Create session to the connection
System.out.println("Creating topic session...");
topicSession = topicConnection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE);
// Get topic name
String topicName = Props.get("topic.name");
// Lookup handle to the Topic
try {
System.out.println("Looking up topic name: " + topicName);
topic = (Topic) context.lookup(topicName);
} catch (NamingException namingException) {
// If not created, create new topic, and bind topic to name
System.out.println("Didn't find the topic...so creating: " + topicName);
topic = topicSession.createTopic(topicName);
System.out.println("Binding topic: " + topicName);
context.bind(topicName, topic);
}
}
catch(Exception e){
System.out.println("PROBLEM CREATING TOPIC MANAGER");
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -