2 回答
TA贡献1842条经验 获得超21个赞
使用调度程序组件并将其配置为使用 spring https://camel.apache.org/components/latest/scheduler-component.html
TA贡献1770条经验 获得超3个赞
我使用 Spring Scheduler 而不是计时器通过使用 ProducerTemplate 调用骆驼路线,参考:https://camel.apache.org/manual/latest/ Producertemplate.html 。
1)春季调度程序:-
@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}");
添加回答
举报