Explain SqsListener concurrency #1203
-
My use case is quite simple - read messages from SQS, transform them and write into relational database(jdbc). Problem is that with all defaults, SqsListener starts 10 threads(I guess it's defined by maxConcurrentMessages) and therefore size of batches being read from SQS is a quite small - it's very rare when it's more than 1 message. But 10 threads writing into DB one record take 10 DB connections. And writing just one record per connection is less than optimal. So, I would prefer less concurrent threads for SqsListener, but bigger batches(even if it takes more polls). And here I struggle to understand how things work. I would assume that logical thing to do is to set So, how do I maximize batch size and minimize concurrency? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
@lazystone it looks like batching consumer would fit your use case well. Have you had a look at https://docs.awspring.io/spring-cloud-aws/docs/3.2.0/reference/html/index.html#batch-processing ? |
Beta Was this translation helpful? Give feedback.
Hi @lazystone, you're correct, if you set maxConcurrentMessages for a value greater than 10 it'll combine the result of multiple polls.
And as @maciejwalkowiak pointed out, that means you'll get messages up to that amount, but SQS does not guarantee to always deliver that amount.
And as you found out, the more messages in SQS, the higher the chances you'll receive full batches.
You don't need to manually configure BATCH mode - just having the List parameter will configure that for you.