gpt4 book ai didi

spring-integration - 如何停止或更改 Spring Integration Poller 的延迟

转载 作者:行者123 更新时间:2023-12-05 05:15:18 29 4
gpt4 key购买 nike

我正在使用 Spring Integration 使用以下配置从目录中读取文件。但是,我希望在找到任何文件后停止轮询,直到服务不再重新启动为止。有什么方法可以在运行时更改轮询器延迟或在运行时启动/停止轮询器?

@Bean
public MessageChannel fileInputChannel() {
return new DirectChannel();
}

@Bean
@InboundChannelAdapter(channel = "fileInputChannel", poller = @Poller(cron = "0 0/10 19-23,0-6 ? * *", maxMessagesPerPoll = "1"))
public MessageSource<File> fileReadingMessageSource() {
FileReadingMessageSource source = new FileReadingMessageSource();
File directory = new File(localFtpDirectory);
if (clearLocalDir && directory.isDirectory() && directory.exists()) {
LOG.info("Clear directory {} on startup of service", directory);
Arrays.stream(directory.listFiles()).forEach(File::delete);
}
source.setDirectory(directory);
source.setFilter(new LastModifiedFileFilter(remoteFileFilter));
return source;
}

@Bean
@ServiceActivator(inputChannel = "fileInputChannel")
public MessageHandler fileHandler() {
return new MessageHandlerService();
}

最佳答案

有这个注释可以与 @InboundChannelAdapter 一起使用:

/**
* When used alongside an EIP annotation (and no {@code @Bean}), specifies the bean name of
* the consumer bean with the handler bean being {@code id.handler} (for a consuming
* endpoint) or {@code id.source} for a message source (e.g. inbound channel adapter).
* <p>
* When there is also a {@code @Bean} annotation, this is the name of the consumer or
* source polling bean (the handler or source gets the normal {@code @Bean} name). When
* using on a {@code MessageHandler @Bean}, it is recommended to name the bean
* {@code foo.handler} when using {@code @EndpointId("foo"}. This will align with
* conventions in the framework. Similarly, for a message source, use
* {@code @Bean("bar.source"} and {@code @EndpointId("bar")}.
* <p>
* <b>This is not allowed if there are multiple EIP annotations on the same method.</b>
*
* @author Gary Russell
*
* @since 5.0.4
*/
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EndpointId {

还有一个 Cotrol 总线 EIP 实现:https://docs.spring.io/spring-integration/docs/5.0.7.RELEASE/reference/html/system-management-chapter.html#control-bus .

有了它,您可以在方便的时候发送 start()/stop() 命令消息。

关于spring-integration - 如何停止或更改 Spring Integration Poller 的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51675977/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com