public class TestJMS {
public final static String
JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
public final static String URL = "t3://water-bfjonvd2b:7001";
private static final String QUEUE_CONNECTION_FACTORY =
"PSJMSConnectionFactory";
private static final String QUEUE = "PSJMSQueue";
static private String user = "root";
static private String password = "12345678";
private static InitialContext getInitialContext(String url) throws
NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
return new InitialContext(env);
} public void testJMS() throws Exception
{
try {
System.out.println("00 TestJMS 00");
Context ctx = getInitialContext(URL);
System.out.println("01 TestJMS 01");
QueueConnectionFactory qConnFact =
(QueueConnectionFactory) ctx.lookup("PSJMSConnectionFactory");
System.out.println("02 TestJMS 02");
QueueConnection qConn = qConnFact.createQueueConnection();
System.out.println("03 TestJMS 03");
QueueSession qSess = qConn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
System.out.println("04 TestJMS 04");
Queue q = (Queue) ctx.lookup(QUEUE);
System.out.println("05 TestJMS 05");
QueueSender qSend = qSess.createSender(q);
TextMessage txtMsg = qSess.createTextMessage("c");
System.out.println("Sending a message to queue");
qSend.send(txtMsg);
//---------------------------------------------------------//
txtMsg = qSess.createTextMessage("a");
System.out.println("Sending a message to queue");
qSend.send(txtMsg);
//---------------------------------------------------------//
qConn.close();
System.exit(0);
}
catch(Exception e)
{
System.out.println("error:"+e.toString()); }
} public TestJMS() {
}}
public final static String
JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
public final static String URL = "t3://water-bfjonvd2b:7001";
private static final String QUEUE_CONNECTION_FACTORY =
"PSJMSConnectionFactory";
private static final String QUEUE = "PSJMSQueue";
static private String user = "root";
static private String password = "12345678";
private static InitialContext getInitialContext(String url) throws
NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
return new InitialContext(env);
} public void testJMS() throws Exception
{
try {
System.out.println("00 TestJMS 00");
Context ctx = getInitialContext(URL);
System.out.println("01 TestJMS 01");
QueueConnectionFactory qConnFact =
(QueueConnectionFactory) ctx.lookup("PSJMSConnectionFactory");
System.out.println("02 TestJMS 02");
QueueConnection qConn = qConnFact.createQueueConnection();
System.out.println("03 TestJMS 03");
QueueSession qSess = qConn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
System.out.println("04 TestJMS 04");
Queue q = (Queue) ctx.lookup(QUEUE);
System.out.println("05 TestJMS 05");
QueueSender qSend = qSess.createSender(q);
TextMessage txtMsg = qSess.createTextMessage("c");
System.out.println("Sending a message to queue");
qSend.send(txtMsg);
//---------------------------------------------------------//
txtMsg = qSess.createTextMessage("a");
System.out.println("Sending a message to queue");
qSend.send(txtMsg);
//---------------------------------------------------------//
qConn.close();
System.exit(0);
}
catch(Exception e)
{
System.out.println("error:"+e.toString()); }
} public TestJMS() {
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货