【问题标题】:Spring Cloud Stream + QuartzSpring Cloud Stream + Quartz
【发布时间】:2017-03-26 07:32:28
【问题描述】:

我计划在我的项目中使用 Spring Cloud Stream。我看到有内置的触发源应用程序启动器。我想做的是使用石英作业调度程序作为源应用程序。这是为了允许来自应用程序的动态作业计划。有没有很好的样本来实现这一目标?

我找到了这个。 spring integration + cron + quartz in cluster?。此解决方案讨论获取对入站通道适配器的引用。我正在使用 Annotation 来定义入站通道适配器。如何获取对该对象的引用,以便我可以执行解决方案中提到的启动/停止。

这就是我定义入站通道适配器的方式。

@Bean
@InboundChannelAdapter(autoStartup = "false", value = SourceChannel.CHANNEL_NAME, poller = @Poller(trigger = "fireOnceTrigger"))
public MessageSource<String> timerMessageSource() {
    return new MessageSource<String>() {
        public Message<String> receive() {
            System.out.println("******************");
            System.out.println("At the Source");
            System.out.println("******************");
            String value = "{\"value\":\"hi\"}";
            System.out.println("Sending value: " + value);
            return MessageBuilder.withPayload(value).setHeader(MessageHeaders.CONTENT_TYPE, "application/json").build();
        }
    };
}

【问题讨论】:

    标签: spring-boot spring-integration spring-cloud-stream


    【解决方案1】:

    GitHub上的相关问题:https://github.com/spring-projects/spring-integration-java-dsl/issues/138

    为自动创建的端点构建 bean 名称的算法如下:

    bean 名称是使用此算法生成的: * MessageHandler (MessageSource) @Bean@Bean 的方法名称或名称属性中获取自己的标准名称。这就像@Bean 方法上没有消息注释一样工作。 * AbstractEndpoint bean 名称使用以下模式生成:[configurationComponentName].[methodName].[decapitalizedAnnotationClassShortName]。例如,上面 consoleSource() 定义的端点 (SourcePollingChannelAdapter) 的 bean 名称如下:myFlowConfiguration.consoleSource.inboundChannelAdapter

    更多信息请参见Reference Manual

    【讨论】:

      猜你喜欢
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 2018-05-18
      • 2017-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多