当前位置: 技术问答>java相关
请问一个使用JMS发送消息的问题:
来源: 互联网 发布时间:2015-08-11
本文导语: 我写了下面一段代码: Queue queue = null; QueueConnectionFactory queueConnectionFactory = null; QueueConnection queueConnection = null; try{ String url = "t3://localhost:7001"; String user = null; Stri...
我写了下面一段代码:
Queue queue = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
try{
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
//Hashtable env = new Hashtable();
//env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
Context jndiContext = new InitialContext(properties);
queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
queue = (Queue)jndiContext.lookup("WroxOrders");
}
catch(NamingException nEx){
System.out.println(nEx.toString() + "nDoes the queue exist?");
System.exit(1);
}
运行的时候提示:
javax.naming.NameNotFoundException: Unable to resolve WroxOrders. Resolved: '' Unresolved:'WroxOrders' ; remaining name ''
程序中WroxOrders指什么?我在weblogic的JMS中看见有几项,我现在只配了个ConnectionFactory和JMSServer,还有需要配什么?我这程序才能正常运行?
Queue queue = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
try{
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
//Hashtable env = new Hashtable();
//env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
Context jndiContext = new InitialContext(properties);
queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
queue = (Queue)jndiContext.lookup("WroxOrders");
}
catch(NamingException nEx){
System.out.println(nEx.toString() + "nDoes the queue exist?");
System.exit(1);
}
运行的时候提示:
javax.naming.NameNotFoundException: Unable to resolve WroxOrders. Resolved: '' Unresolved:'WroxOrders' ; remaining name ''
程序中WroxOrders指什么?我在weblogic的JMS中看见有几项,我现在只配了个ConnectionFactory和JMSServer,还有需要配什么?我这程序才能正常运行?
|
你没有配置消息队列