Spring JMS出站通道适配器

时间:2013-08-05 17:46:46

标签: spring jms integration channel outbound

我是Spring Integration的新手。我缺乏它的基础知识。

我们有一个要求,即轮询一个状态为0的oracle数据库表,并以XML格式将该记录发送到JMS队列。

jdbc:入站通道适配器正在拾取记录并转向jms出站通道适配器,这应该非常简单。但我有以下两个问题

1)我看到有多少消费者在activeMQ管理控制台中有1个用于我的需求和配置,所以我不想在队列上监听所有我想要的消息是将消息发送到队列。

2)交易未提交。我点击它时看到的消息没有消息。 如果停止我的进程消息被提交。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:task="http://www.springframework.org/schema/task" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc" 
    xmlns:int-jms="http://www.springframework.org/schema/integration/jms" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:stream="http://www.springframework.org/schema/integration/stream"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd 
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
        http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
        http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.0.xsd">

<!--    <import resource="context.xml"/> -->
<!--     <context:Resource name="jms/mqConnectionFactory"   -->
<!--               auth="Container"   -->
<!--               type="org.apache.activemq.ActiveMQConnectionFactory"   -->
<!--               description="JMS Connection Factory"   -->
<!--              factory="org.apache.activemq.jndi.JNDIReferenceFactory"   -->
<!--               brokerURL="tcp://localhost:61616" />   -->
    <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
        <property name="connectionFactory">
          <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL">
              <value>${activemq.brokerurl}</value>
            </property>
          </bean>
        </property>
     </bean>

     <bean id="defaultDestination" class="org.apache.activemq.command.ActiveMQQueue">
        <constructor-arg index="0" value="${jms.queue.name}"/>
    </bean>

<!--         <context:Resource name="jms/CM_TO_UIS"   -->
<!--               auth="Container"   -->
<!--               type="org.apache.activemq.command.ActiveMQQueue"   -->
<!--               factory="org.apache.activemq.jndi.JNDIReferenceFactory"   -->
<!--               physicalName="TEST_AMQ"/>  -->
    <bean id="splitterBean" class="edu.bc.academic.coursepolling.integration.MessageSplitter" />
    <bean id="contentTransformerBean" class="edu.bc.academic.coursepolling.integration.ContentTransformer" />
    <bean id="productRouterBean" class="edu.bc.academic.coursepolling.integration.ProductRouter" />
    <poller default="true" max-messages-per-poll="1" receive-timeout="5000"
        fixed-delay="5000"
        xmlns="http://www.springframework.org/schema/integration">
        <transactional />
    </poller>

    <int:channel id="jdbcChannel">
        <int:interceptors>
            <int:wire-tap channel="logger" />
        </int:interceptors>
    </int:channel>

    <int:logging-channel-adapter id="logger" level="ERROR" />

    <int-jdbc:inbound-channel-adapter 
    channel="jdbcChannel" 
    query="${int.poll.query}" 
         data-source="dataSource" max-rows-per-poll="1"

        update="update COURSE_POLLER_T set status=1 where COURSE_POLLER_ID in (:COURSE_POLLER_ID)">

    </int-jdbc:inbound-channel-adapter>

    <int-jdbc:outbound-channel-adapter
        query="update COURSE_POLLER_T set status=-1 where COURSE_POLLER_ID in (:payload[COURSE_POLLER_ID])"
        data-source="dataSource" channel="rejectedMessagesChannel" />

    <int:publish-subscribe-channel id="rejectedMessagesChannel" />

    <int:chain input-channel="jdbcChannel" >
        <int:splitter ref="splitterBean"/>
<!--        <int:service-activator ref="service" method="process" /> -->
        <int:router ref="productRouterBean" method="route" />
<!--        <int:transformer ref="contentTransformerBean" method="transform"/> -->
    </int:chain>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${int.jdbc.driver}" />
        <property name="url" value="${int.jdbc.url}" />
        <property name="username" value="${int.jdbc.user}" />
        <property name="password" value="${int.jdbc.password}" />
    </bean>

    <bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:int-${ENVIRONMENT}.properties" />
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="order" value="1" />
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="service" class="edu.bc.academic.coursepolling.integration.CoursePollerService" />

<!--    <stream:stdout-channel-adapter id="replyChannel"></stream:stdout-channel-adapter> -->

<!--    <bean id="taskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler"> -->
<!--        <property name="poolSize" value="${int.scheduler.pool.size}" /> -->
<!--    </bean> -->

<!--    <int-jms:outbound-channel-adapter id="jmsOut" destination="outQueue"  channel="exampleChannel"/> -->
<!--   connection-factory="jmsFactory"
     destination="defaultDestination"-->
    <int-jms:channel id="jmsSenderChannel" queue="defaultDestination" connection-factory="jmsFactory" />
    <int-jms:outbound-channel-adapter id="jmsOut"   channel="jmsSenderChannel" 
     jms-template="jmsOutputTemplate" >
    </int-jms:outbound-channel-adapter>


   <bean id="jmsOutputTemplate" class="org.springframework.jms.core.JmsTemplate">
      <property name="connectionFactory" ref="jmsFactory"/>
      <property name="defaultDestination" ref="defaultDestination"/>
      <property name="deliveryPersistent" value="true"/>
      <property name="sessionTransacted" value="true"/>
      <property name="sessionAcknowledgeMode" value="0"/>
   </bean>
</beans>

提前致谢

0 个答案:

没有答案