这看起来像一个重复的问题,我查看了the question here about transaction managers和引用的文档部分,但没有成功。
我想到的流程是处理xml文件:
带有事务管理器的入站通道适配器 - >频道 - >服务激活
该文件被传递到我的java程序进行处理就好了。然后,我希望事务管理器部分将处理过的文件移动到一个文件夹中,将失败的文件移动到另一个后半部分是我的问题。我有这个配置:
<int-file:inbound-channel-adapter id="pgen-inbound" directory="file:D:/records/incoming/" auto-startup="true" filter="compositeFilter" channel="pgen-inchannel">
<int:poller fixed-rate="1000">
<int:transactional transaction-manager="transactionManager" synchronization-factory="fileSync"/>
</int:poller>
</int-file:inbound-channel-adapter>
<bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager"/>
<int:transaction-synchronization-factory id="fileSync">
<int:after-commit expression="payload.renameTo('./success/' + payload.name)" channel="nullChannel" />
<int:after-rollback expression="payload.renameTo('./failed/' + payload.name)" channel="nullChannel" />
</int:transaction-synchronization-factory>
<int:channel id="pgen-inchannel"/>
<int:service-activator input-channel="pgen-inchannel" ref="recordProcessor" method="processInboundRecords"/>
<bean id="recordProcessor" class="com.a.b.RecordFeeder">
<property name="username" value="pgenuser"/>
<property name=".../>
...
</bean>
<bean id="compositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
<constructor-arg value="*.xml"/>
</bean>
</list>
</constructor-arg>
</bean>
目录全部存在,但文件未移动且没有错误消息,只记录:
INFO org.springframework.integration.file.FileReadingMessageSource- Created message: [GenericMessage [payload=D:\records\incoming\record2.xml, headers={id=f24b11e4-39ac-03e1-6b3c-cae7ff5b7615, timestamp=1468404043936}]]
我的理解是,我不需要从事务同步工厂开始的通道,因为它们只会传递payload.renameTo操作的结果,即。是真还是假,因此我在那里使用了nullChannel。
我得到了这个记录:
DEBUG org.springframework.integration.handler.ServiceActivatingHandler- handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@1e05e138] (org.springframework.integration.config.ServiceActivatorFactoryBean#0)' produced no reply for request Message: GenericMessage [payload=D:\records\incoming\pgImpor2.xml, headers={id=4860011b-b6a3-9dbd-8572-90b12de88e9c, timestamp=1468423768506}]
DEBUG org.springframework.integration.channel.DirectChannel- postSend (sent=true) on channel 'pgen-inbound', message: GenericMessage [payload=D:\records\incoming\pgImpor2.xml, headers={id=4860011b-b6a3-9dbd-8572-90b12de88e9c, timestamp=1468423768506}]
DEBUG org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor- Sending received message to org.springframework.integration.channel.NullChannel@4fc66eb8 as part of 'beforeCommit' transaction synchronization
DEBUG org.springframework.integration.channel.NullChannel- message sent to null channel: GenericMessage [payload=D:\record\incoming\pgImpor2.xml, headers={id=4860011b-b6a3-9dbd-8572-90b12de88e9c, timestamp=1468423768506}]
DEBUG org.springframework.orm.jpa.JpaTransactionManager- Initiating transaction commit
DEBUG org.springframework.orm.jpa.JpaTransactionManager- Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@36411551]
DEBUG org.springframework.orm.jpa.JpaTransactionManager- Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@36411551] for JPA transaction
DEBUG org.springframework.orm.jpa.JpaTransactionManager- Participating in existing transaction
DEBUG org.springframework.orm.jpa.JpaTransactionManager- Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@36411551] for JPA transaction
DEBUG org.springframework.orm.jpa.JpaTransactionManager- Participating in existing transaction
**DEBUG org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor- Evaluating afterCommit expression: 'payload.renameTo('./success/' + payload.name)' on GenericMessage [payload=D:\record\incoming\pgImpor2.xml, headers={id=4860011b-b6a3-9dbd-8572-90b12de88e9c, timestamp=1468423768506}]**
DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory- Returning cached instance of singleton bean 'integrationEvaluationContext'
DEBUG org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor- Sending expression result message to nullChannel as part of 'afterCommit' transaction synchronization
DEBUG org.springframework.integration.channel.NullChannel- message sent to null channel: GenericMessage [payload=false, headers={id=339dda35-55cc-c6db-68e5-fc84fe32ff04, timestamp=1468423781333}]
DEBUG org.springframework.orm.jpa.JpaTransactionManager- Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@36411551] after transaction
DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils- Closing JPA EntityManager
因此它评估了对成功案例的renameTo调用..但是没有设置任何结果。