Spring JMS + IBM MQ:如何设置消息缓冲区大小或等待超时?
我无法处理来自IBM MQ的大消息并得到以下错误:
I'm unable to process large messages from IBM MQ and get the below error:
JMSCMQ0001:WebSphere MQ调用失败,compcode为'1'('MQCC_WARNING'),原因为'2080'('MQRC_TRUNCATED_MSG_FAILED')
JMSCMQ0001: WebSphere MQ call failed with compcode '1' ('MQCC_WARNING') reason '2080' ('MQRC_TRUNCATED_MSG_FAILED')
我正在使用DefaultListenerContainer,而不是通过直接使用IBM MQ Java API类的MessageConsumer进行消费.我相信通过使用IBM MQ JMS API,您可以在从队列中检索消息之前指定特定的选项.但是如何使用DefaultListenerContainer做到这一点,是否可以为它们设置系统属性?
I'm using the DefaultListenerContainer and not consuming via a MessageConsumer using IBM MQ Java API classes directly. I believe by using IBM MQ JMS API you can specific options before retrieving the message from the queue. But how do I do that with DefaultListenerContainer, is there a system property I can set for these?
如果使用IBM MQ JMS API(我不使用这样的消息,仅将其粘贴以供参考):
If using IBM MQ JMS API(I'm not consuming message like this, pasted just for reference):
MQGetMessageOptions mqGetMessageOptions = new MQGetMessageOptions(); mqGetMessageOptions.waitInterval = ipreoProperties.getMqReceiveWaitTime(); mqGetMessageOptions.options = MQC.MQGMO_WAIT | MQC.MQPMO_SYNCPOINT | MQC.MQGMO_ACCEPT_TRUNCATED_MSG;
MQGetMessageOptions mqGetMessageOptions = new MQGetMessageOptions(); mqGetMessageOptions.waitInterval = ipreoProperties.getMqReceiveWaitTime(); mqGetMessageOptions.options = MQC.MQGMO_WAIT | MQC.MQPMO_SYNCPOINT | MQC.MQGMO_ACCEPT_TRUNCATED_MSG;
以下是我的IBM MQ连接的Java Config:
Below is my Java Config for the IBM MQ Connection:
@Bean
public CachingConnectionFactory ipreoMQCachingConnectionFactory() {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
//Not defining MQQueueConnectionFactory as separate bean as Spring boot's auto-configuration finds two instances
//of ConnectionFactory and throws ambiguous implementation exception
//One implementation is CachingConnectionFactory and other one would be MQQueueConnectionFactory if defined separately
MQQueueConnectionFactory mqConnectionFactory = new MQQueueConnectionFactory();
try {
mqConnectionFactory.setHostName(env.getRequiredProperty(AppEnvPropertyConstants.JmsConstants.IPREO_MQ_HOSTNAME));
mqConnectionFactory.setQueueManager(env.getRequiredProperty(AppEnvPropertyConstants.JmsConstants.IPREO_MQ_QUEUE_MGR));
mqConnectionFactory.setPort(env.getRequiredProperty(AppEnvPropertyConstants.JmsConstants.IPREO_MQ_PORT, Integer.class));
mqConnectionFactory.setChannel(env.getRequiredProperty(AppEnvPropertyConstants.JmsConstants.IPREO_MQ_CHANNEL));
//mqConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
//Setting connection mode as Client so it doesn't complain for native IBM MQ libraries
mqConnectionFactory.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
} catch (JMSException exception) {
exception.printStackTrace();
}
cachingConnectionFactory.setTargetConnectionFactory(mqConnectionFactory);
//Setting session caching size as 10, don't think we need more
cachingConnectionFactory.setSessionCacheSize(10);
cachingConnectionFactory.setReconnectOnException(true);
return cachingConnectionFactory;
}
public DefaultMessageListenerContainer ipreoDealActivityListenerContainer() {
DefaultMessageListenerContainer factory = new DefaultMessageListenerContainer();
factory.setConnectionFactory(ipreoMQCachingConnectionFactory());
factory.setDestinationName(env.getRequiredProperty(AppEnvPropertyConstants.JmsConstants.IPREO_DEAL_QUEUE_NAME));
factory.setMessageListener(ipreoDealActivityListener());
factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
return factory;
}
@Bean
public MessageListener ipreoDealActivityListener() {
return new IpreoDealActivityListener();
}
感谢您的帮助,谢谢.
我们自动处理的接收缓冲区的JMS客户端代码处理;从理论上讲,JMS应用程序永远都不应接收到特定的错误.
Within the JMS client code handling of the receive buffer us handled automatically; the theory is that specific error should never be received by a JMS Application.
第一段代码是Java Classes API,这可能会导致该错误.
The first snippet of code is the Java Classes API and this could get that error.
这些消息实际上有多大?您正在使用什么级别的JMS客户端代码-确保它是最新版本.当然是7.5或8版本之一.
How big actually are these messages? What level of the JMS client code are you using - make sure that it is the latest version. And certainly one of the 7.5 or 8 releases.
此答案还提供了更多信息在此.
This answer also has some more information on this.