[英]spring integration - read file from FTP and process it. How can we achieve metastore and process it without polling
In spring integration - Im trying to read file from FTP and process it. 在春季集成中-我试图从FTP读取文件并进行处理。 How can we achieve metastore and process it without polling. 我们如何实现元存储并在不进行轮询的情况下对其进行处理。 In the below configuration, in order to avoid reading the same file, if server restart happen ,I have introduced message-store in the ftpChannel. 在下面的配置中,为了避免读取相同的文件,如果服务器重新启动,我在ftpChannel中引入了消息存储。 Now, the processor of the file is service activator, which needs polling. 现在,文件的处理器是服务激活器,需要轮询。 How can i avoid polling in service activator and read the file from ftpChannel queue immediately. 如何避免在服务激活器中轮询并立即从ftpChannel队列中读取文件。 If i use int:dispatcher then, I couldnot use message-store. 如果我使用int:dispatcher,那么我将无法使用消息存储。
How can we resolve this? 我们该如何解决呢?
<int:channel id="ftpChannel">
<int:queue message-store="mongoDbMessageStore" />
<!-- <int:dispatcher task-executor="taskExecutor"/> -->
</int:channel>
<bean id="mongoDbMessageStore"
class="org.springframework.integration.mongodb.store.MongoDbMessageStore">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
<constructor-arg name="collectionName" value="ftpInfo" />
</bean>
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel" session-factory="ftpClientFactory" charset="UTF-8"
auto-create-local-directory="true" delete-remote-files="false"
filename-pattern="*.gz" remote-directory="/myfilerepo/#{istDate.getISTDate()}"
remote-file-separator="/" local-filename-generator-expression="#this.toUpperCase()"
temporary-file-suffix=".writing" preserve-timestamp="true"
local-directory="/temp/spring/#{istDate.getISTDate()}">
<int:poller cron="0-5 0/5 * * * ?" max-messages-per-poll="-1"/>
</int-ftp:inbound-channel-adapter>
<int:service-activator id="jobServiceActivator"
input-channel="ftpChannel" ref="triggerJobLauncher" method="launch">
<int:poller fixed-delay="10" />
</int:service-activator>
<!-- job context -->
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<!-- job context -->
You do not need a message-store
on the channel; 您不需要在频道上message-store
; you need to use an FtpPersistentAcceptOnceFileListFilter in the filter
and/or a FileSystemPersistentAcceptOnceFileListFilter in the local-filter
to avoid reprocessing files after a system restart. 您需要在filter
使用FtpPersistentAcceptOnceFileListFilter和/或在local-filter
使用FileSystemPersistentAcceptOnceFileListFilter以避免系统重新启动后重新处理文件。
They need a MetadataStore
; 他们需要一个MetadataStore
; if you want to use mongo you'll need to implement one; 如果要使用mongo,则需要实现一个; the framework currently doesn't have a mongo implementation. 该框架目前没有mongo实现。
EDIT: 编辑:
As of version 4.2, the framework now has a mongo MetadataStore
. 从4.2版开始,该框架现在具有mongo MetadataStore
。
According to your concern to avoid reading the same file from the QueueChannel
, I'd say that you worry that Spring Application always process the same message after application startup. 根据您的担心, to avoid reading the same file from the QueueChannel
,我想说您担心Spring Application在应用程序启动后总是处理相同的消息。 But it isn't true. 但这不是真的。 The message are removed from the queue (and, of course, from the MessageStore
) when it is polled
from there. 从队列中polled
消息后,该消息将从队列中删除(当然,也从MessageStore
中删除)。 If you MessageStore
is transactional resource (eg JDBC), the record for messages is marked to remove until TX commit or rollback. 如果您的MessageStore
是事务性资源(例如JDBC),则将消息记录标记为删除,直到TX提交或回滚为止。 It isn't case for MongoDB though, but any message from the queue are polled only once, even if you have a cluster of such an application. 不过,对于MongoDB而言,情况并非如此,但是,即使您拥有此类应用程序的集群,队列中的任何消息也只会被轮询一次。
So, I don't understand why are you sure that your <service-activator>
accepts the same file (as payload
) because you restart the app. 因此,我不明白您为什么确定您的<service-activator>
接受相同的文件(作为payload
),因为您重新启动了该应用程序。
From other side, if you want to access to the MessageGroup
backed by your ftpChannel
, you can do this: 从另一方面来看,如果要访问ftpChannel
支持的MessageGroup
,则可以执行以下操作:
mongoDbMessageStore.getMessageGroup("mongoDbMessageStore:ftpChannel");
From other side you always can purge
QueueChannel
manually, injection ftpChannel
to some service as QueueChannelOperations
. 从另一方面来看,您始终可以手动purge
QueueChannel
,将ftpChannel
作为QueueChannelOperations
注入到某些服务中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.