Sending multiple http requests with Apache Camel

╄→гoц情女王★ 提交于 2021-01-07 01:30:52

问题


I am trying to send GET HTTP requests to a paginated endpoint. The challenge is I do not know the page size beforehand therefore I have to send a request to get page number and interate till the end. I have tried Camel HTTP but I was not able to make it send dynamic requests based on first (or previous) response. I am currently testing recipientList to generate HTTP URLs by sending the first request and use the simple method as processor. Since Camel is really new for me, I am not sure if this is the best way to do like this.

I would be really grateful if someone could show some direction on this. Thank you


回答1:


When I understood your question correct, you have to make an initial request to get the first page.

In the response you probably get the number of pages and then you want to get all remaining pages.

You could give the Camel Loop EIP a try for the remaining pages.

Pseudo-Route:

.from("whatever triggers the page retrieval")
    .setHeader("currentPage", constant(1))
    .to("http:target/page/1")
    // dont know what you want to do with the pages
    ... continue processing of the first page
    .setHeader("numberOfPages", simple("extract the number of pages somehow"))
    .loopDoWhile(simple("${header.currentPage} <= ${header.numberOfPages}"))
        .toD("http:target/page/${header.currentPage}")
        // dont know what you want to do with the pages
        ... continue processing of the current page
    .end

It really depends on what you need to do with the pages you retrieve. For example if you have to aggregate them, I am not sure if you can access an aggregated result from inside the loop.



来源:https://stackoverflow.com/questions/65338202/sending-multiple-http-requests-with-apache-camel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!