简体   繁体   English

春季集成-从FTP读取文件并进行处理。 我们如何实现元存储并在不进行轮询的情况下对其进行处理

[英]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.

相关问题 从远程位置进行文件轮询的问题,连接成功,但使用FTP Spring Integration从本地目录读取 - Issue with File Polling from remote location, connection success but read from local directory with FTP Spring Integration 如何使用Spring Integration DSL进行Ftp轮询 - how to do Ftp polling with Spring integration DSL 我如何在一个Java进程中创建和写入文件并从另一个进程中读取而不会遇到读/写问题(Java / EE) - How can I create and write a File one Java Process and read from another process without facing read/write problems(Java/EE) 在 Spring Integration 中使用 Transformer 轮询 HTTP 服务(出站网关)和流程 - Polling HTTP Service(Outbound Gateway) & process using Transformer in Spring Integration 使用Spring Integration计划通过FTP进行远程文件下载并处理内存中的文件 - Schedule remote file download over FTP and process file in memory with Spring Integration 在带有集成的Spring Batch中将文件上传为并行过程 - File upload as parallel process in spring batch with integration 如何实现从android应用中的http服务器获取实时事件? 没有轮询 - How can I achieve to get live events from a http server on an android app? without polling Spring SFTP 集成未轮询文件 - Spring SFTP Integration is not polling the file 如何在弹簧集成中并行和同步处理? - how to process in parallel and synchronously in spring integration? Spring 集成:逐行处理文件持久读取 state - Spring integration: process files line by line persisting read state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM