本文介绍了弹簧云功能[Azure] TimerTrigger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都有Spring cloud Function [Azure] TimerTrigger示例实现?请共享

Anybody has Spring cloud Function [Azure] TimerTrigger sample implementation ?Please do share

推荐答案

通过执行以下操作(基于HttpTrigger代码),我可以使其运行:

I was able to get this running by doing the following (this is based off the HttpTrigger code):

  1. 创建具有TimerTrigger的处理程序:
@Component
public class TimerHandler extends AzureSpringBootRequestHandler<User, Greeting> {

    @FunctionName("timedTrigger")
    public void timedTrigger(
            @TimerTrigger(name = "trigger", schedule = "0 */30 * * * *") String timerInfo,
            ExecutionContext context) {

        // We need to invoke the handleRequest so our spring function (defined as a bean) will be invoked.
        Greeting g = handleRequest(new User("Trigger"), context);
    }
}
  1. 添加您的bean(与上面的函数同名).
@SpringBootApplication(
        scanBasePackages = "your.package.structure"
)
public class SpringApp {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(TimedHandler.class);
    }

    @Bean
    public Function<User, Greeting> timedTrigger() {        
        return user -> new Greeting("Welcome, " + user.getName());
    }

}
  1. 完成基本工作后,可以修改 AzureSpringBootRequestHander 类型和 Function 类型.
  1. After you get the base working you can modify the AzureSpringBootRequestHander type and the Function types.

这篇关于弹簧云功能[Azure] TimerTrigger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 20:29