我需要从oracle AQ中读取消息。我正在使用Spring Boot 2.2.0.RELEASE。目前,我只能在我的spring boot应用程序已启动时阅读消息。但是,如果AQ已将消息放入队列,则不会将其出队。 我不知道怎么了。
我的配置类:
@Configuration
@EnableJms
public class BridgeConfiguration {
@Bean
DataSource dataSource() throws SQLException {
OracleDataSource dataSource = new OracleDataSource();
dataSource.setUser("user");
dataSource.setPassword("pwd");
dataSource.setURL("jdbc:oracle:thin:host:1521/sid");
dataSource.setImplicitCachingEnabled(true);
dataSource.setFastConnectionFailoverEnabled(true);
return dataSource;
}
@Bean
// @Qualifier(value = "aqconnectionFactory")
public QueueConnectionFactory aqconnectionFactory() throws Exception {
return AQjmsFactory.getQueueConnectionFactory(dataSource());
}
@Bean
public PlatformTransactionManager transactionManager() throws Exception {
JmsTransactionManager jmsTransactionManager = new JmsTransactionManager();
jmsTransactionManager.setConnectionFactory(aqconnectionFactory());
return jmsTransactionManager;
}
@Bean
public JmsListenerContainerFactory jmsListenerContainerFactory() throws Exception {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(aqconnectionFactory());
factory.setTransactionManager(transactionManager());
factory.setSessionTransacted(true);
return factory;
}
}
我的听众课
@Component
public class AqDaoImpl {
@JmsListener(destination = "IBMBRIDGE_OUT", concurrency = "3-10")
public void getMessage(String message) {
try{
System.out.println(message + " received on " + Thread.currentThread().getName());
}catch (Exception e ){
System.out.println(e);
}
}
}
我希望我将能够接收已经入队的消息。但是,如果我关闭我的应用程序,将一些消息放入oracle aq中,然后打开它的应用程序无法接收到该消息,则消息会保留在oracle aq中。