?? jms102example.java
字號:
package jms102;
import javax.naming.*; // The JNDI classes
import javax.jms.*; // The JMS 1.02 classes
public class JMS102Example {
public QueueSender getQueueSender(String queueConnectionFactoryName, String queueName)
throws NamingException, JMSException {
// Get the specified connection factory and queue
Context jndiContext = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory)
jndiContext.lookup(queueConnectionFactoryName);
Queue queue = (Queue) jndiContext.lookup(queueName);
// Create the connection and session
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
// Use the session and queue to create the sender
QueueSender sender = session.createSender(queue);
return sender;
}
public TopicPublisher getTopicPublisher(String topicConnectionFactoryName, String topicName)
throws NamingException, JMSException {
// Get the specified connection factory and queue
Context jndiContext = new InitialContext();
TopicConnectionFactory factory = (TopicConnectionFactory)
jndiContext.lookup(topicConnectionFactoryName);
Topic topic = (Topic) jndiContext.lookup(topicName);
// Create the connection and session
TopicConnection connection = factory.createTopicConnection();
TopicSession session = connection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// Use the session and topic to create the publisher
TopicPublisher publisher = session.createPublisher(topic);
return publisher;
}
public QueueReceiver getQueueReceiver(String queueConnectionFactoryName, String queueName)
throws NamingException, JMSException {
// Get the specified connection factory and queue
Context jndiContext = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory)
jndiContext.lookup(queueConnectionFactoryName);
Queue queue = (Queue) jndiContext.lookup(queueName);
// Create the connection and session
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
// Use the session and queue to create the receiver
QueueReceiver receiver = session.createReceiver(queue);
return receiver;
}
public TopicSubscriber getTopicSubscriber(String topicConnectionFactoryName, String topicName)
throws NamingException, JMSException {
// Get the specified connection factory and queue
Context jndiContext = new InitialContext();
TopicConnectionFactory factory = (TopicConnectionFactory)
jndiContext.lookup(topicConnectionFactoryName);
Topic topic = (Topic) jndiContext.lookup(topicName);
// Create the connection and session
TopicConnection connection = factory.createTopicConnection();
TopicSession session = connection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// Use the session and topic to create the subscriber
TopicSubscriber subscriber = session.createSubscriber(topic);
return subscriber;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -