【发布时间】:2016-03-26 10:27:31
【问题描述】:
我无法处理来自 IBM MQ 的大消息并收到以下错误:
JMSCMQ0001:WebSphere MQ 调用失败,compcode '1' ('MQCC_WARNING') 原因 '2080' ('MQRC_TRUNCATED_MSG_FAILED')
我正在使用 DefaultListenerContainer,而不是直接使用 IBM MQ Java API 类通过 MessageConsumer 进行消费。我相信通过使用 IBM MQ JMS API,您可以在从队列中检索消息之前使用特定选项。但是我如何使用 DefaultListenerContainer 来做到这一点,我可以为这些设置系统属性吗?
如果使用 IBM MQ JMS API(我不使用这样的消息,粘贴仅供参考):
MQGetMessageOptions mqGetMessageOptions = new MQGetMessageOptions(); mqGetMessageOptions.waitInterval = ipreoProperties.getMqReceiveWaitTime(); mqGetMessageOptions.options = MQC.MQGMO_WAIT | MQC.MQPMO_SYNCPOINT | MQC.MQGMO_ACCEPT_TRUNCATED_MSG;
以下是我用于 IBM MQ 连接的 Java 配置:
@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();
}
感谢您的帮助,谢谢。
【问题讨论】:
标签: spring-boot ibm-mq spring-jms