使用 Apache Camel 发送多个 http 请求 [英] Sending multiple http requests with Apache Camel

查看:216
本文介绍了使用 Apache Camel 发送多个 http 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 GET HTTP 请求发送到分页端点.挑战是我事先不知道页面大小,因此我必须发送请求以获取页码并交互直到最后.我尝试过 Camel HTTP,但我无法让它根据第一个(或以前的)响应发送动态请求.我目前正在测试 recipientList 以通过发送第一个请求并使用简单的 method 作为处理器来生成 HTTP URL.由于 Camel 对我来说真的很新,我不确定这是否是最好的方法.

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

推荐答案

当我理解你的问题是正确的,你必须提出一个初始请求以获得第一页.

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.

你可以试试 Camel Loop EIP其余页面.

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

伪路由:

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

这篇关于使用 Apache Camel 发送多个 http 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆