?? qmproducer.java
字號:
package jms.client;
import javax.jms.QueueConnectionFactory;
import javax.jms.*;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.Queue;
import javax.jms.QueueSender;
import javax.jms.TextMessage;
import javax.jms.JMSException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
public class QMProducer {
public static void main(String[] args) {
Properties jndiEnv = new Properties();
jndiEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
jndiEnv.setProperty(Context.PROVIDER_URL, "t3://localhost:7001");
QueueConnection con = null;
QueueSession session = null;
QueueSender sender = null;
try {
Context ctx = new InitialContext(jndiEnv);
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup(
"jms/QueueConnectionFactory");
con = factory.createQueueConnection();
session = con.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Queue q = (Queue) ctx.lookup("jms/fileQueue");
sender = session.createSender(q);
TextMessage msg = session.createTextMessage();
msg.setText("Hello World");
sender.send(msg);
}
catch (NamingException ne) {
ne.printStackTrace();
}
catch (JMSException je) {
je.printStackTrace();
}
finally{
if(sender !=null)try{sender.close();}catch(JMSException je){}
if(session !=null)try{session.close();}catch(JMSException je){}
if(con !=null)try{con.close();}catch(JMSException je){}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -