Java 如何使用spring调度程序而不是Camel计时器启动Camel路由
如何使用spring调度器而不是计时器组件启动驼峰路由 我曾尝试使用camel timer组件来触发路由,但有任何方法可以使用spring调度器而不是timer来触发路由 1)春季主要课程:-Java 如何使用spring调度程序而不是Camel计时器启动Camel路由,java,spring-boot,apache-camel,Java,Spring Boot,Apache Camel,如何使用spring调度器而不是计时器组件启动驼峰路由 我曾尝试使用camel timer组件来触发路由,但有任何方法可以使用spring调度器而不是timer来触发路由 1)春季主要课程:- @SpringBootApplication public class SampleSchedulerApplication { public static void main(String[] args) { SpringApplication.run(SampleSchedul
@SpringBootApplication
public class SampleSchedulerApplication {
public static void main(String[] args) {
SpringApplication.run(SampleSchedulerApplication.class, args);
}
}
2)路由器类别:-
@SpringBootApplication
public class SampleSchedulerApplication {
public static void main(String[] args) {
SpringApplication.run(SampleSchedulerApplication.class, args);
}
}
下面是我尝试使用计时器组件的示例
//Directing to someService
from("timer://scheduler?period=10s")//What component should i use by default.
.to("direct:someservice");
//Fetching datas from the rest api.
from("direct:someservice")
.setHeader(Exchange.HTTP_METHOD).constant(HttpMethod.GET)
.to("undertow:http://localhost:8090/api/employee/getemployees").
.log("Response : ${body}");
without timer, i can't able to trigger the route.
使用调度程序组件并将其配置为使用spring
我使用spring调度程序调用了驼峰路线,而不是使用ProducerTemplate调用了计时器 参考: 1) Spring调度程序:-
@Configuration
@EnableScheduling
public class SchedulerConfiguration {
@Autowired
private IntegrationService integrationService;
@Scheduled(fixedDelay = 90000, initialDelay = 5000)
public void integrationConfig() throws IOException {
integrationService.getServiceAuthentication();
}
2) 综合服务
@Component
public class IntegrationService {
@Autowired
private ProducerTemplate producerTemplate;
public void getServiceAuthentication() {
producerTemplate.sendBody("direct:someservice","username=123&password=123");
}
}
3) 路由器生成器类
from("direct:someservice")
.setHeader(Exchange.HTTP_METHOD).constant(HttpMethod.GET)
.to("undertow:http://localhost:8090/api/employee/getemployees").
.log("Response : ${body}");