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

2024-05-22

我正在使用 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 {

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

这样你就可以发送start()/stop()在您方便的时候发送命令消息。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何停止或更改 Spring Integration Poller 的延迟 的相关文章

随机推荐

  • WooCommerce 从前端(而不是管理员)隐藏订单项元

    我有一些我不希望客户看到的订单项元详细信息 在帐户信息下的查看订单页面上 我找到了一个过滤器 可以从管理员 我仍然希望看到它 中删除这些数据 但找不到类似的过滤器来从前端 应该隐藏它 中删除它 这是将从后端管理中删除它的代码 对我来说毫无用
  • 在 Swift 中动态设置 Dictionary 的属性

    我正在尝试根据字典中的值在类上设置一些属性 目前我正在这样做 let view UIView UIView if let hidden Bool self props hidden as Bool view hidden hidden if
  • 如何使用Excel的墨迹工具添加手写签名?

    我想在我公司的一些表格中添加手写数字签名 目标是选择一个文档 添加签名 通过使用绘图板 这可以使用 Excel 的墨水工具完成 并将文件作为 PDF 存储在服务器中 这将消除打印然后扫描表格以获得签名的必要性 我使用 Excel 作为文件操
  • html 元视口标签

    我建立了一个html登陆页面 你可以看到它here http tzabar exactive co il 我以这种方式使用元视口标签 当我从手机进入这个页面时 页面宽度不适合屏幕 iPhone 示例 http mobiletest me i
  • 英特尔融核上的 MKL 性能

    我有一个例程 对小矩阵 50 100 x 1000 个元素 执行一些 MKL 调用以拟合模型 然后我调用不同的模型 在伪代码中 double doModelFit int model while done cblas dgemm cblas
  • 如何使用 RSpec 测试 javascript 重定向?

    我正在使用 xhr post 与控制器交互 并且我期待重定向 在 js erb 中 我有 window location href address 手动测试 浏览器会正确重定向 我如何使用 RSpec 测试它 response should
  • 如何记录所有抛出的异常?

    如何记录抛出和捕获的任何异常 就像 Visual Studio 的 IntelliTrace 所做的那样 或者有没有办法将 InteliTrace 集成到应用程序的调试版本中 然后查看其日志 Update 我会稍微澄清一下 我想要标准 tx
  • 如何设置Codeigniter上传库在本地机器的上传路径?

    我将以下路径设置为 Codeigniter 附带的上传库的 upload path this gt upload config upload path uploads working 该路径在远程服务器上运行良好 但是 当我在本地调试时 它
  • Maven 插件前缀解析如何工作?为什么它解决了“findbugs”而不是“jetty”?

    我正在使用 Maven 进行一些测试 并意识到我可以执行findbugsFindbugs 插件的目标 无需将插件添加到 POM 文件 另一方面 当我需要运行runJetty 插件的目标 我被迫将插件添加到 POM 文件中 否则构建失败 为什
  • 用于全文搜索和 2 亿多条记录的数据库

    我即将创建一个包含至少 2 亿个条目的庞大数据库 数据库需要可使用全文进行搜索 并且速度应该很快 我的数据库从许多不同的数据源获取数据 我需要定期导入新的或更新的数据 将我的所有数据存储在像 mysql 这样的关系数据库中 然后创建一个 n
  • Mercurial 与 Visual Studio 2010 的白痴清单

    所以我是一个源代码控制白痴 所以请用这个清单来幽默我 我最终决定使用Mercurial TortoiseHg VS2010 HgScc包 http bitbucket org zzsergant hgsccpackage wiki Home
  • (发件人:TObject)

    发件人 TObject 是什么意思 如 procedure TForm1 Button1Click Sender TObject var s Integer begin end Sender 是对触发事件的组件的引用 在这种情况下 Send
  • Android 缩放和密度问题

    Update 一些研究表明 华硕 Transformer TF700T 高端 的像素密度应约为 224 因此 android 报告的 159 值要么是错误的 要么已被某种方式修改 system 中的 lcd 密度键 build prop 由
  • Spring Security 的 AJAX 请求给出 403 Forbidden

    我有一个基于spring boot spring security thymeleaf的网站 在某些情况下我也使用ajax 问题 我在 Spring Security 中使用表单登录安全性 在浏览器中 登录后我可以使用rest API GE
  • 如何更改ios中FBSDKLoginButton中的默认登录按钮?

    如何自定义 Facebook 中的登录按钮 我不想使用 Facebook 默认登录按钮 对于 SDK 4 0 您应该添加一个按钮 并在按钮操作中使用以下代码 IBAction loginButtonClicked id sender FBS
  • 如何将 java ArrayList 转换为等效的 double[] [重复]

    这个问题在这里已经有答案了 可能的重复 如何在 Java 中从 List 转换为 double https stackoverflow com questions 6018267 how to cast from listdouble to
  • 在多个 angular.js 应用程序之间共享单个服务

    我正在构建一个电子商务网站 基于 shopify 并且使用多个小型 angularjs 应用程序来处理诸如快速购物车 愿望清单 过滤产品和其他一些较小项目之类的事情 我最初使用了一个大型应用程序 具有路由和所有内容 但当我没有完整的 RES
  • 缓存消息discord.js

    我想做一些反应角色 但为此 我必须缓存机器人启动之前发送的消息 我尝试过channel messages fetch 但到目前为止还没有奏效 我当前的代码 client on messageReactionAdd async reactio
  • 如何在 Metro 应用程序中从 Web 上下文(Iframe)发出 javascript 警报。

    在我的 Metro 应用程序中 我使用 iframe 加载 Web 应用程序 基本上是一个包含一些控件的表单 最后用户单击 完成 按钮 我想显示警报 我在地铁应用程序中知道 我们可以使用 new Windows UI Popup Messa
  • 如何停止或更改 Spring Integration Poller 的延迟

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