Spring Cloud Stream + Quartz

左心房为你撑大大i 提交于 2021-01-27 13:23:31

问题


I am planning to use Spring cloud Stream for my project. I see that there's built-in Trigger source application starter. What I want to do is to use, quartz job scheduler as the source app. This is to allow dynamic job schedules from application. Is there a good sample to achieve this?

I found this. spring integration + cron + quartz in cluster?. This solution talks about getting reference to inbound channel adapter. I am using Annotation to define the inbound channel adapter. How do I get references to this object so that I can do start / stop mentioned in the solution.

This is how i define inbound channel adapter.

@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();
        }
    };
}

回答1:


The related issue on GitHub: https://github.com/spring-projects/spring-integration-java-dsl/issues/138

The algorithm to build a bean name for automatically created endpoints is like:

The bean names are generated with this algorithm: * The MessageHandler (MessageSource) @Bean gets its own standard name from the method name or name attribute on the @Bean. This works like there is no Messaging Annotation on the @Bean method. * The AbstractEndpoint bean name is generated with the pattern: [configurationComponentName].[methodName].[decapitalizedAnnotationClassShortName]. For example the endpoint (SourcePollingChannelAdapter) for the consoleSource() definition above gets a bean name like: myFlowConfiguration.consoleSource.inboundChannelAdapter.

See Reference Manual for more information.



来源:https://stackoverflow.com/questions/40558655/spring-cloud-stream-quartz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!