?? jms11example.java
字號:
package jms11;
import javax.naming.*; // The JNDI classes
import javax.jms.*; // The JMS 1.1 classes
public class JMS11Example {
public MessageProducer getProducer(String connectionFactoryName, String destinationName)
throws NamingException, JMSException {
// Get the specified connection factory and queue
Context jndiContext = new InitialContext();
ConnectionFactory factory = (ConnectionFactory)
jndiContext.lookup(connectionFactoryName);
Destination destination = (Destination) jndiContext.lookup(destinationName);
// Create the connection and session
Connection connection = factory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// Use the session and destination to create the producer
MessageProducer producer = session.createProducer(destination);
return producer;
}
public MessageConsumer getConsumer(String connectionFactoryName, String destinationName)
throws NamingException, JMSException {
// Get the specified connection factory and queue
Context jndiContext = new InitialContext();
ConnectionFactory factory = (ConnectionFactory)
jndiContext.lookup(connectionFactoryName);
Destination destination = (Destination) jndiContext.lookup(destinationName);
// Create the connection and session
Connection connection = factory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// Use the session and destination to create the consumer
MessageConsumer consumer = session.createConsumer(destination);
return consumer;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -