📄 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 + -