MDB类实现了MessageListener(javax.jms.MessageListener),这个ejb打包为ear,并部署在IBM WAS 8.0上。
MDB侦听队列。 只要队列中有消息,MDB就会尝试侦听该队列,并立即给出以下异常。
例外:
[4/27/16 18:09:50:420 CDT] 000000c2 SibMessage W [:] CWSJY0003W: MQJCA1003: The message endpoint has no onMessage() method. Deployment failed.
[4/27/16 18:09:50:431 CDT] 000000c2 SibMessage W [:] CWSJY0003W: JMSCC0109: A message driven bean threw a runtime exception '
Message : java.lang.RuntimeException: no onMessage() method
Class : class java.lang.RuntimeException
Stack : com.ibm.mq.connector.inbound.MessageEndpointWrapper.onMessage(MessageEndpointWrapper.java:142)
: com.ibm.mq.jms.MQSession$FacadeMessageListener.onMessage(MQSession.java:147)
: com.ibm.msg.client.jms.internal.JmsSessionImpl.run(JmsSessionImpl.java:2846)
: com.ibm.mq.jms.MQSession.run(MQSession.java:862)
: com.ibm.mq.connector.inbound.WorkImpl.run(WorkImpl.java:297)
: com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:608)
: com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)
'.
[4/27/16 18:09:50:431 CDT] 000000c2 SibMessage W [:] CWSJY0003W: MQJCA4004: Message delivery to an MDB '{project#className}' failed with exception: 'no onMessage() method'
[4/27/16 18:09:50:469 CDT] 000000c2 ActivationSpe I J2CA0524I: The Message Endpoint for ActivationSpec {activationspec JNDI} (com.ibm.mq.connector.inbound.ActivationSpecImpl) and MDB Application {project#className} is deactivated.
对实现MessageListener
进行分类import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.ejb.MessageDriven;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@MessageDriven(
name = "MDBClass",
activationConfig = { @ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty( propertyName = "destination", propertyValue ="jms/queue")
}
)
public class MDBClass implements MessageListener {
private static final Logger logger = LoggerFactory.getLogger(MDBClass.class);
TextMessage txtMsg = null;
String strMsg = null;
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void onMessage(Message message) {
if (message instanceof TextMessage) {
txtMsg = (TextMessage) message;
try {
strMsg = txtMsg.getText();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
}
不确定我错过了什么。