亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Spring Scheduler 而不是 Camel Timer 啟動 Camel 路線

如何使用 Spring Scheduler 而不是 Camel Timer 啟動 Camel 路線

慕村225694 2023-10-13 16:28:50
如何使用 spring 調度程序而不是計時器組件啟動駱駝路線?我嘗試過使用駱駝計時器組件來觸發路線,但是除了計時器之外,還有什么方法可以使用 spring 調度程序來觸發路線。1)Spring主類:-@SpringBootApplicationpublic class SampleSchedulerApplication {    public static void main(String[] args) {        SpringApplication.run(SampleSchedulerApplication.class, args);    }}2) 路由器類別:-以下是我嘗試使用計時器組件的示例。//Directing to someServicefrom("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.
查看完整描述

2 回答

?
茅侃侃

TA貢獻1842條經驗 獲得超21個贊

使用調度程序組件并將其配置為使用 spring https://camel.apache.org/components/latest/scheduler-component.html


查看完整回答
反對 回復 2023-10-13
?
德瑪西亞99

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}");


查看完整回答
反對 回復 2023-10-13
  • 2 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號