1

I have small doubt regarding how polling thread behaves.

Let us take a scenario where i have maxNumberOfMessages to be received per poll is 10. And We are using DEFAULT_WAIT_TIME = 20 seconds. I want to know how it behaves in different scenarios mentioned below.

  1. If there are 5-6 messages in queue. Then how many can be returned? And will polling thread wait for some time to get more messages?
  2. If there are no messages in queue, will it wait till it gets one messages or will it wait for more than that?
  3. If there are above 10 messages in queue, then how will it behave?

1 Answers1

0
  1. If there are fewer messages in the queue than you're waiting for then some number less than or equal to the number of messages available will be returned. In your example, you may get all 6 but you may only get 3 and have to poll again for the rest.
  2. If there are no messages then the polling will wait as long as your timeout is (20 seconds in your case) and return an empty list.
  3. The 10 message version may return all 10 messages but it might not. As in question 1, keep reading to get them all.

What I have seen is that if you had 100 messages then you're much more likely to get them all but it's still no guarantee.

stdunbar
  • 16,263
  • 11
  • 31
  • 53
  • Any idea which we can't have consistent behaviour? And also what if we have zero waiting time? Will anything change in case 1. – Shiva Peddi Apr 09 '19 at 14:00
  • Why does it matter? In general, you'll be sitting in a polling loop, processing messages. If you get 1 you process it. If you get 10 you process them. If you get zero then you'll do nothing. A zero wait time will end up burning CPU and potentially money when there is nothing in the queue. – stdunbar Apr 09 '19 at 14:54