I am trying to get tweets from my Twitter timeline with ConsumerTemplate (Camel) in a Quarkus app.
I don't understand how it should be done correctly while using rate limits (my free account has rate 15 polls in 5 min).
The Camel setup has property count which I set to 10, and expect to get 10 new tweets in one poll, but the problem is that template offers only one tweet per Camel request:
for (int i = 0; i < 15; i++) {
// I would expect here List or stream, but I can get only single `Status`
final Status tweets = consumerTemplate.receiveBodyNoWait(String.format("twitter-timeline://home?sinceId=%s&count=10", sinceId), Status.class);
// just to show that I change that property
if (nonNull(tweets)) {
sinceId = tweets.getId();
}
}
So my question is why I get only one tweet per poll even if count is set (a value more than 1). Is there any better way or running that template, or something I can use instead while respecting downstream Twitter rate limits?
The
ConsumerTemplateis based on aPollingConsumerunder the hood, which as the name implies, pullsExchages one at a time hence why you are receiving only 1Status(== 1Exchange) even while setting acountendpoint option.It is almost hard (and error-prone) to implement tweets (or other
Exchanges) consumption the right way. Indeed this is already offered out-of-the-box with the Apache Camel Twitter Component consumer.Here down a sample of a route to consume user public activity (timeline) using the twitter-timeline component:
This will leverage the default polling configured delays which you can tweak based on your preferences to address any rate-limits. In your case for example, to respect 15 requests per 5 mins, you can set the consumer to poll each 20 seconds for one page: