Fork me on GitHub
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!))


SQS client has built-in long-polling support if max 20sec interval is OK for you


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. 🙂


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.


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

👍 1

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 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