Fork me on GitHub
#aws
<
2022-08-04
Ian Fernandez14:08:15

are there any examples of aws sqs using cognitect aws-api?

Ian Fernandez14:08:37

I would like to reach out an example for retrieving messages from time to time

Ian Fernandez14:08:43

(require '[promesa.core :as p])

(defonce consume-sqs-scheduler-running
  (atom true))

(def consume-sqs-scheduler
  (let [{::keys [event-pull-seconds]} config]
    (p/loop []
      (p/delay (* 1000 event-pull-seconds))
      (when @consume-sqs-scheduler-running
        (handle-sqs-data (pull-sqs-data! config))
        #_(println ::RUN!))
      (p/recur))))

valtteri15:08:35

SQS client has built-in long-polling support if max 20sec interval is OK for you https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-sqs-long-polling.html

valtteri15:08:59

Sorry, I don’t have an example how to use that with cognitect aws-api but just wanted to point out this as an option. 🙂

valtteri15:08:48

Oh wait… cognitect aws-api uses the API directly and there’s no “official” aws-client involved.. So you’ll probably need to build the delay mechanism yourself. Your example with promesa looks like a an OK starting point. It’s very simple and probably works. If you you need something more robust I’d look into quarts (maybe a bit overkill), tea-time or similar scheduler.

valtteri15:08:01

Or.. since you’re on AWS.. it’s also possible to schedule a lambda to periodically read the queue

👍 1
valtteri15:08:48

Actually.. it would be kinda interesting if someone has figured out how to do long-polling with cognitect aws-api

Karol Wójcik15:08:03

I would go for Lambda. Typically you want consume message & dead letter queue. This is very easy to setup with Lambda.

jjttjj17:08:30

https://github.com/RutledgePaulV/piped is an SQS client implemented with aws-api, might be worth checking out the source code

Ian Fernandez14:08:56

if it's not possible, I'll do something like this