可以在Spring @JmsListener目标中使用JNDI名称吗?

时间:2016-10-05 15:05:45

标签: spring jms jndi spring-jms spring-java-config

Spring 4.2.4WebSphere MQ 7.xJBoss 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查找)成功地放入队列。

0 个答案:

没有答案