amazonica icon indicating copy to clipboard operation
amazonica copied to clipboard

using different Amazon*Clients for multhreading

Open pablobcb opened this issue 7 years ago • 3 comments

Hello,

I have an application using SQS, and i'd like to consume/process it from different threads ... but after the msgs are in flight, the other threads cant fetch new msgs

Looking at the docs ive found:

Note: The first function called (for each distinct AWS service namespace, e.g. amazonica.aws.ec2)
 creates an Amazon*Client, which is effectively cached via memoization. Therefore, if you explicitly pass different credentials maps to different functions, you will effectively have different Clients.

I guess this is the reason behind it.. is there a way to use individual clients (or another proper solution) so each thread can process its own batch (of 10 msgs) ?

thanks!

pablobcb avatar Dec 06 '17 20:12 pablobcb

you can consume from the queue inside multiple (future....)

mcohen01 avatar Dec 06 '17 20:12 mcohen01

Not sure if I got it right ... lets suppose I have 100 msgs (0 in-flight), and I'd like to print them all this should do the trick?

(dotimes [_ 10]
  (future
   (let [payload (sqs/receive-message aws-cfg
                   {:max-number-of-messages 10
                    :queue-url              queue-url})]
     (prn payload))))

Because right now the first thread print 10 msgs and the other 9 receive an empty list (like there are no msgs in the queue)

thank you for the fast response!

pablobcb avatar Dec 07 '17 18:12 pablobcb

you may want to try adding wait-time-seconds to your receive-message calls

mcohen01 avatar Dec 08 '17 08:12 mcohen01