Spring JMS Oracle AQ 事务过多

发布于 2025-01-03 11:08:57 字数 8315 浏览 1 评论 0原文

我创建了一个基本的 Spring 应用程序来读取 Oracle AQ。我遇到以下问题。请在这方面帮助我

1)- 在启动我的 Spring 应用程序之前放置在队列上的消息(通过 PL/SQL 代码)不会被它出列。 2)- 从队列中成功读取的消息应从队列中删除。这并没有发生。所有消息都保留在队列表中。 3)- 一旦读取了一条消息,进程就会进入阻塞/等待状态,如下面的日志所示,如果在此期间有任何消息放入队列,则该消息将被忽略。提交事务需要 30 - 40 秒

2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer] - <Received message of type [class oracle.jms.AQjmsAdtMessage] from consumer [oracle.jms.AQjmsConsumer@1989b5] of transactional session [oracle.jms.AQjmsSession@189c036]>
2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - <Mapping column 'id' to property 'id' of type class java.math.BigDecimal>
2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - <Mapping column 'type_cd' to property 'type_cd' of type class java.lang.String>
2012-02-08 13:26:37,700 INFO [com.test.oracle.aq.ProductDelegate] - <Product [id=6, type_cd=Test Product Code]>
2012-02-08 13:26:37,715 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - <Executing SQL update [INSERT INTO Product(id, type_cd) values(6, 'Test Product Code')]>
2012-02-08 13:26:37,731 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - <SQL update affected 1 rows>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@1860038]>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@1860038] after transaction>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>

4)- 为什么会进行如此多的事务?在等待队列时

2012-02-08 13:22:58,937 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@9b688e] for JDBC transaction>
2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@9b688e] to manual commit>
2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@9b688e]>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@9b688e] after transaction>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@eca36e] for JDBC transaction>
2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@eca36e] to manual commit>
2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@eca36e]>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@eca36e] after transaction>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@19b4748] for JDBC transaction>
2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@19b4748] to manual commit>
2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@19b4748]>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@19b4748] after transaction>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:02,311 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@1a41cc7] for JDBC transaction>

下面是我的 spring 配置

<bean id="dataSource" class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
    <property name="URL" value="jdbc:oracle:thin:@//localhost:1521/XE" />
    <property name="user" value="migration" />
    <property name="password" value="password" />
</bean>
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
    lazy-init="true">
    <property name="dataSource" ref="dataSource" />
</bean>
<bean id="messageDelegate" class="com.test.oracle.aq.ProductDelegate" />
<jms:listener-container connection-factory="connectionFactory"   
    transaction-manager="transactionManager"
    message-converter="messageConverter" 
    container-class="org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer" destination-type="topic">
    <jms:listener destination="MIGRATION.PRODUCT_QUEUE" ref="messageDelegate" method="handleMessage" />
</jms:listener-container>
<bean id="messageConverter"                                                          
        class="org.springframework.data.jdbc.jms.support.converter.oracle.MappingAdtMessageConverter">
    <constructor-arg>
        <bean class="org.springframework.data.jdbc.jms.support.oracle.StructDatumMapper">
            <constructor-arg index="0" value="MIGRATION.PRODUCT_T"/>
            <constructor-arg index="1" value="com.test.oracle.aq.Product"/>
        </bean>
    </constructor-arg>
</bean>
<orcl:aq-jms-connection-factory id="connectionFactory" data-source="dataSource"/> 
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="sessionTransacted" value="true"/>
</bean>

I have created a basic Spring applicatin to read from Oracle AQ. I am experiencing following issues. Kindly help me on this

1)- Messages placed on the queue (by PL/SQL code) prior to starting of my spring application are not dequeued by it.
2)- A message that is successfull read from the queue should be removed from the queue. This is not happening. All messages remain in Queue Table.
3)- Once a message is read, the process goes in block/waiting state, as shown by the log below, if any message is place on queue during that period, that message is ignored. It is taking 30 - 40 secs to commit the transaction

2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer] - <Received message of type [class oracle.jms.AQjmsAdtMessage] from consumer [oracle.jms.AQjmsConsumer@1989b5] of transactional session [oracle.jms.AQjmsSession@189c036]>
2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - <Mapping column 'id' to property 'id' of type class java.math.BigDecimal>
2012-02-08 13:26:37,700 DEBUG [org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper] - <Mapping column 'type_cd' to property 'type_cd' of type class java.lang.String>
2012-02-08 13:26:37,700 INFO [com.test.oracle.aq.ProductDelegate] - <Product [id=6, type_cd=Test Product Code]>
2012-02-08 13:26:37,715 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - <Executing SQL update [INSERT INTO Product(id, type_cd) values(6, 'Test Product Code')]>
2012-02-08 13:26:37,731 DEBUG [org.springframework.jdbc.core.JdbcTemplate] - <SQL update affected 1 rows>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@1860038]>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@1860038] after transaction>
2012-02-08 13:26:57,295 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>

4)- Why it is making soo many tansactions? While waiting on queue

2012-02-08 13:22:58,937 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@9b688e] for JDBC transaction>
2012-02-08 13:22:59,000 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@9b688e] to manual commit>
2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:00,045 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@9b688e]>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@9b688e] after transaction>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:00,061 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@eca36e] for JDBC transaction>
2012-02-08 13:23:00,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@eca36e] to manual commit>
2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:01,154 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@eca36e]>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@eca36e] after transaction>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:01,155 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@19b4748] for JDBC transaction>
2012-02-08 13:23:01,202 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Switching JDBC Connection [oracle.jdbc.driver.T4CConnection@19b4748] to manual commit>
2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Initiating transaction commit>
2012-02-08 13:23:02,263 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Committing JDBC transaction on Connection [oracle.jdbc.driver.T4CConnection@19b4748]>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Releasing JDBC Connection [oracle.jdbc.driver.T4CConnection@19b4748] after transaction>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - <Returning JDBC Connection to DataSource>
2012-02-08 13:23:02,278 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Creating new transaction with name [org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer#0]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT>
2012-02-08 13:23:02,311 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - <Acquired Connection [oracle.jdbc.driver.T4CConnection@1a41cc7] for JDBC transaction>

Below are my spring config

<bean id="dataSource" class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
    <property name="URL" value="jdbc:oracle:thin:@//localhost:1521/XE" />
    <property name="user" value="migration" />
    <property name="password" value="password" />
</bean>
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
    lazy-init="true">
    <property name="dataSource" ref="dataSource" />
</bean>
<bean id="messageDelegate" class="com.test.oracle.aq.ProductDelegate" />
<jms:listener-container connection-factory="connectionFactory"   
    transaction-manager="transactionManager"
    message-converter="messageConverter" 
    container-class="org.springframework.data.jdbc.jms.listener.oracle.AdtMessageListenerContainer" destination-type="topic">
    <jms:listener destination="MIGRATION.PRODUCT_QUEUE" ref="messageDelegate" method="handleMessage" />
</jms:listener-container>
<bean id="messageConverter"                                                          
        class="org.springframework.data.jdbc.jms.support.converter.oracle.MappingAdtMessageConverter">
    <constructor-arg>
        <bean class="org.springframework.data.jdbc.jms.support.oracle.StructDatumMapper">
            <constructor-arg index="0" value="MIGRATION.PRODUCT_T"/>
            <constructor-arg index="1" value="com.test.oracle.aq.Product"/>
        </bean>
    </constructor-arg>
</bean>
<orcl:aq-jms-connection-factory id="connectionFactory" data-source="dataSource"/> 
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="sessionTransacted" value="true"/>
</bean>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文