Reputation: 260
I do have a project developed in Quakrkus using Apache Camel which does interact with external APIs and saves the details to the database. Currently, it interacts with external APIs to fetch the details, and the sample response from that external API is as below
{
"totalSize": 3,
"limit": 1,
"offset": 2,
"records": [
{
...
}
]
}
Apache Camel code is as below which uses the above external API and the requirement is to support the pagination based on limit, offset and totalSize. I have found some looping feature of apache camel but not sure how I can use them
@RegisterForReflection
@ApplicationScoped
public class SalesForceAccountRouter extends BaseRouter {
@Inject
AccountRepository accountRepository;
@Override
public void configure() throws Exception {
super.configure();
from("direct:salesforce-account")
.removeHeaders("*")
.log("Fetching records from SF Account with request URL::: "
+ "{{sales.s.url}}/accounts?${exchangeProperty.query}")
.toD("{{sales.s.url}}/accounts?${exchangeProperty.query}")
.unmarshal()
.json(JsonLibrary.Gson, PaginationResponse.class)
.process(new SalesForceAccountProcessor(accountRepository))
.marshal()
.json(JsonLibrary.Gson)
.end()
.log("End route");
}
}
Upvotes: 0
Views: 638
Reputation: 11600
Salesforce pagination works via a field in the query result called nextRecordsUrl
. There are many ways to approach this. Here's one:
// do initial salesforce query and unmarshal
...
.setProperty("nextRecordsUrl", simple("${body.nextRecordsUrl}"))
// process query results
...
.loopDoWhile(simple("${exchangeProperty.nextRecordsUrl} != null"))
// query salesforce using nextRecordsUrl
.toD("${exchangeProperty.nextRecordsUrl}")
// unmarshal
.setProperty("nextRecordsUrl", simple("${body.nextRecordsUrl}"))
// process query results
.end()
Upvotes: 1