我遇到了 JBoss EAP 6 和 WebSphere MQ 的问题。我开发了一个消息驱动的bean:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/VGT.EXTERN.IN"),
@ActivationConfigProperty(propertyName = "clientID", propertyValue = "VGT_BYSENDINGSYSTEMDISPATCHERMDB") })
@Pool(value = "BySendingSystemDispatcherMDB-pool")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class BySendingSystemDispatcherMDB implements javax.jms.MessageListener {
private Logger logger = Logger.getLogger(getClass());
@Inject
@Named
BySendingSystemDispatcher bySendingSystemDispatcher;
@Resource
MessageDrivenContext mdc;
@Inject
@Named
Listener listener;
@Override
public void onMessage(Message message) {
try {
// Weiterbearbeitung deligieren
bySendingSystemDispatcher.onMessage(message);
} catch (JMSException e) {
listener.handleExceptionWhenMessageIsPoisend(e);
logger.error(e.getLinkedException(), e);
mdc.setRollbackOnly();
} catch (JAXBException e) {
mdc.setRollbackOnly();
listener.handleExceptionWhileProcessingMessage(message, e);
logger.error(e.getMessage(), e);
} catch (ClassCastException e) {
logger.error(e.getMessage(), e);
mdc.setRollbackOnly();
} catch (Exception e) {
logger.error(e.getMessage(), e);
mdc.setRollbackOnly();
} finally {
// logging
if (logger.isDebugEnabled()) {
String id = null;
try {
id = message.getJMSMessageID();
logger.debug(((TextMessage) message).getText());
} catch (Exception e) {
logger.debug("logging of message - " + id + " failed");
}
}
}
}
bySendingSystemDispatcher.onMessage(message) 方法抛出了一个从 java.lang.Exception 派生的异常,并用 @ApplicationException(rollback=true) 注释。如果发生这种情况,消息将按照配置重新传递 5 次,之后它会在资源适配器中循环,不再传递。我用 HornetQ 检查了相同的场景,它按预期工作。
MQ 会抛出以下异常
Class : class javax.jms.JMSException
Stack : com.ibm.msg.client.commonservices.trace.Trace.ffst(Trace.java:1611)
: com.ibm.msg.client.wmq.common.internal.messages.WMQSendMarshal.constructMQMD(WMQSendMarshal.java:287)
: com.ibm.msg.client.wmq.common.internal.messages.WMQSendMarshal.exportMQMDAndMessageBuffers(WMQSendMarshal.java:503)
: com.ibm.msg.client.wmq.common.internal.messages.WMQSendMarshal.exportMQMD(WMQSendMarshal.java:567)
: com.ibm.msg.client.wmq.internal.WMQPoison$PoisonMessage.calculateMqmdAndBuffers(WMQPoison.java:1816)
: com.ibm.msg.client.wmq.
一个有趣的点是,您可以在 MQMD 标头中找到超过回退阈值的回退计数。
知道会发生什么以及如何解决吗?
约尔格