簡體   English   中英

如何使用 spring 調度程序而不是駱駝計時器來啟動駱駝路線

[英]How to start the Camel route using spring scheduler instead of camel timer

如何使用 spring 調度程序而不是計時器組件啟動駱駝路線?

我曾嘗試使用駱駝計時器組件來觸發路由,但有什么方法可以使用 spring 調度程序來觸發路由,而不是計時器。

1) Spring 主要 class:-

@SpringBootApplication
public class SampleSchedulerApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleSchedulerApplication.class, args);
    }
}

2) 路由器 class:-

以下是我嘗試使用計時器組件的示例。

//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.

Use the scheduler component and configure it to use spring https://camel.apache.org/components/latest/scheduler-component.html

I have called camel route using spring scheduler instead of timer by using ProducerTemplate refer: 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)路由器生成器Class;

 from("direct:someservice")                
.setHeader(Exchange.HTTP_METHOD).constant(HttpMethod.GET)              
.to("undertow:http://localhost:8090/api/employee/getemployees").
.log("Response : ${body}");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM