问题
We have an implementation where messages are being placed on an AWS SQS queue and being consumed by Camel AWS. We are using concurrentConsumers = 1. We are logging the polling of the queue as done by org.apache.camel.component.aws.sqs.SqsConsumer .
The test consists of sending a message to SQS (from a remote system) and then logging the time the message is on the queue. On the Camel end, we have trace logging on the SqsConsumer class, and we can see when the queue is polled, and when messages are consumed.
If we place a message on the queue every 10 seconds, most times Camel picks up the message in 1-2 seconds. However, there are many times when it takes significantly longer (10+ seconds).
Basically we see this behavior:
- (Remote)Place message on SQS
- (Camel)Poll
- (Camel)Poll
- (Camel)Poll
- ... (for many polls, default 500 milliseconds apart)
- (Camel)Receive message from SQS
We have tested SQS end to end without Camel and there is no issue with throughput (1000 messages in a few seconds).
Our Camel implementation for this test consists only of reading from the SQS queue and logging - there is no other functionality.
We have tested with altering many of the other Camel SQS parameters, with no difference in behavior.
However, if we test with concurrentConsumers = 10, for example, every message is picked up from the queue almost instantly, with minimal delay.
My question is why doesn't the single consumer pick up messages in a timely manner? If it is truly polling every 500 milliseconds, how is it not "seeing" and picking up the messages?
Note - we are hesitant to enable the multi-threading that comes with using concurrentConsumers because of the functionality of our application.
回答1:
As suggested by @ketanvijayvargiya, long polling indeed seems to be the answer. We took a second look at it because of your comment. There are multiple ways to set the value that we tried :
- Via camel itself on the SQS URI, ?receiveMessageWaitTimeSeconds=
- Setting it on the AWS SQS queue itself (on the console, Configure Queue -> Receive Message Wait Time).
We had tested (2) and didn't see any behavior change (at the time of my post). We tested again using (1) and saw improvements. We retested with (2) again and also saw improvements, so we can only assume that we had made a mistake when performing the first test.
来源:https://stackoverflow.com/questions/41992529/apache-camel-not-acquiring-message-from-sqs-in-timely-manner