Spring 4.2.4
,WebSphere MQ 7.x
和JBoss EAP 6.4
。
考虑以下JmsConfig
:
@Bean
@Profile("all")
public ConnectionFactory devConnectionFactory() {
ConnectionFactory cf = null;
JndiObjectFactoryBean connection = new JndiObjectFactoryBean();
connection.setJndiName(connectionFactoryName);
connection.setProxyInterface(ConnectionFactory.class);
connection.afterPropertiesSet();
cf = (ConnectionFactory) connection.getObject();
return cf;
}
@Bean
public JndiDestinationResolver jndiDestinationResolver() {
JndiDestinationResolver jdr = new JndiDestinationResolver();
return jdr;
}
@Bean
JmsListenerContainerFactory<?> jmsContainerFactory(ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setConcurrency(getConcurrency());
factory.setRecoveryInterval(new Long(getRecoveryInterval()));
factory.setAutoStartup(new Boolean(this.getAutoStartup()));
factory.setTransactionManager(this.jmsTransactionManager());
factory.setSessionTransacted(true);
factory.setDestinationResolver(jndiDestinationResolver());
return factory;
}
@Bean
public JmsTransactionManager jmsTransactionManager() {
return new JmsTransactionManager(this.devConnectionFactory());
}
JmsListener
:
@JmsListener(destination = "${jms.jndi.inqueue}", containerFactory = "jmsContainerFactory", selector = "version='001' AND eventtype is null")
public void onMessageVersion1(Message message) throws JMSException {
BusinessLog.log("MQ inbound message", message);
processMessageHeaderVersionMatched(message);
}
${jms.jndi.inqueue}
是JNDI名称。我认为JndiDestinationResolver
能够干预并正确处理它,但事实并非如此。
不会发生异常或错误,但不会从队列中提取消息。
还可以添加Messages
可以使用相同的设置(ConnectionFactory
JNDI查找)成功地放入队列。