我正在研究EJB中的Message Driven Bean示例。我创建了部署在weblogic服务器和Client项目中的EJB项目,它使用JNDI名称将消息发送到MDB。我还在weblogic控制台中创建了JMS Queue和Queue ConnectionFactory。
但问题是在客户端,它无法识别队列的JNDI名称。
EJB项目中的OueueListenerMDB.java
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/weblogic.wsee.DefaultQueue")
},
mappedName = "mdb")
public class QueueListenerMDB implements IQueueListenerMDB{
public QueueListenerMDB() {
}
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
System.out.println("Queue: I received a TextMessage at "
+ new Date());
TextMessage msg = (TextMessage) message;
System.out.println("Message is : " + msg.getText());
} else if (message instanceof ObjectMessage) {
System.out.println("Queue: I received an ObjectMessage at "
+ new Date());
ObjectMessage msg = (ObjectMessage) message;
Employee employee = (Employee) msg.getObject();
System.out.println("Employee Details: ");
System.out.println(employee);
} else {
System.out.println("Not valid message for this Queue MDB");
}
} catch (JMSException e) {
e.printStackTrace();
}
}
}
客户端项目上的QueueSenderDemo.java
public class QueueSenderDemo {
private static final String PROVIDER_URL = "t3://localhost:7002/";
private static final String INITIAL_CONTEXT_FACTORY = "weblogic.jndi.WLInitialContextFactory";
private static Context initialContext;
private static final String QUEUE_LOOKUP = "jms/weblogic.wsee.DefaultQueue";
private static final String CONNECTION_FACTORY = "jms/weblogic.jms.ConnectionFactory";
public static void main(String[] args) throws NamingException {
sendMessageToQueue();
}
public static void sendMessageToQueue() {
try {
Context context = getInitialContextForClient();
QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup(CONNECTION_FACTORY);
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) context.lookup(QUEUE_LOOKUP);
QueueSender sender = session.createSender(queue);
TextMessage message = session.createTextMessage("Welcome to EJB3 Message Driven Bean.");
sender.send(message);
session.close();
} catch (NamingException e) {
e.printStackTrace();
} catch (JMSException e) {
e.printStackTrace();
}
}
public static Context getInitialContextForClient()
throws NamingException {
if (initialContext == null) {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
prop.put(Context.PROVIDER_URL, PROVIDER_URL);
initialContext = new InitialContext(prop);
}
return initialContext;
}
}
我在运行像这样的客户端程序时遇到错误。
javax.naming.NameNotFoundException: While trying to lookup 'jms.weblogic.wsee.DefaultQueue' didn't find subcontext 'wsee'. Resolved 'jms.weblogic' [Root exception is javax.naming.NameNotFoundException: While trying to lookup 'jms.weblogic.wsee.DefaultQueue' didn't find subcontext 'wsee'. Resolved 'jms.weblogic']; remaining name 'wsee/DefaultQueue'
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at weblogic.jndi.internal.ServerNamingNode_1035_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:423)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:411)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.mdbclient.utility.QueueSenderDemo.sendMessageToQueue(QueueSenderDemo.java:36)
at com.mdbclient.utility.QueueSenderDemo.main(QueueSenderDemo.java:27)
Caused by: javax.naming.NameNotFoundException: While trying to lookup 'jms.weblogic.wsee.DefaultQueue' didn't find subcontext 'wsee'. Resolved 'jms.weblogic'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:247)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:667)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:522)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:518)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:667)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:522)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:518)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
答案 0 :(得分:0)
确保您的子部署/定位指向正确的服务器。您的队列可能托管在受管服务器上,并且您尝试在错误的受管服务器或管理服务器上查找。如果您可以显示定位或jndi树,则可以更轻松地提供帮助。