JmsTemplate.receiveAndConvert()问题与ADT有效负载有关

时间:2014-04-30 21:09:22

标签: java spring

我尝试使用Spring的JmsTemplate从队列中同步接收消息。我的设置非常简单,基于文章here。每当我调用receiveAndConvert()时,我都会收到以下错误:

  

JMS-137:必须为具有ADT的目的地指定有效负载工厂   有效载荷

我知道这与将有效负载转换为对象实例的过程有关。但是,您可以在下面查看,我已经设置了Spring数据转换器。此外,使用相同的设置发送邮件也可以正常工作。

配置:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:lang="http://www.springframework.org/schema/lang" xmlns:orcl="http://www.springframework.org/schema/data/orcl"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/lang 
        http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/batch 
        http://www.springframework.org/schema/batch/spring-batch.xsd
        http://www.springframework.org/schema/data/orcl
        http://www.springframework.org/schema/data/orcl/spring-data-orcl-1.0.xsd">
    <!-- This job processes transactions in the pending queue and create entries 
        in the processed transactions table. -->

    <!-- Enables communicating with the database -->
    <bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>database.properties</value>
    </property>
</bean>

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource"
    destroy-method="close">
    <property name="URL" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="connectionCachingEnabled" value="true" />
</bean>

<!-- Basic Spring Batch classes -->
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="jobRepository"
    class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
</bean>

<bean id="jobLauncher"
    class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
</bean>

    <!-- Beans used by the job -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg index="0" ref="dataSource" />
    </bean>

    <!-- Connection Factory used by the JmsTemplate -->
    <orcl:aq-jms-connection-factory id="connectionFactory"
        data-source="dataSource" use-local-data-source-transaction="true" />

    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="sessionTransacted" value="true" />
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="defaultDestinationName" value="SPRINGBATCH.PENDING_TRAN_ITEM_QUEUE" />
        <property name="receiveTimeout" value="100"/>
        <property name="messageConverter">
            <bean
                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="SPRINGBATCH.PENDING_TRANSACTION_ITEM" />
                        <constructor-arg index="1"
                            value="com.sbe.jobs.createPendingTransactionsAndLoadQueue.PendingTransactionKey" />
                    </bean>
                </constructor-arg>
            </bean>
        </property>
    </bean>

1 个答案:

答案 0 :(得分:0)

我最终发现了问题所在。似乎JmsTemplate不支持ADT类型,因此对此link

  

自定义高级数据类型(ADT)(CREATE TYPE xxx AS OBJECT):

     
    

此     有效负载类型需要一个名为的自定义消息监听器容器     AdtMessageListenerContainer。这个监听器容器也可以使用     具有Oracle AQ ADT特定消息转换器的MessageListenerAdapter     指定为MappingAdtMessageConverter。这个转换器使用     DatumMapper接口的实现。见下文     配置细节。