Clojure agents consuming from a queue

后端 未结 4 997
梦如初夏
梦如初夏 2020-12-13 04:41

I\'m trying to figure out the best way to use agents to consume items from a Message Queue (Amazon SQS). Right now I have a function (process-queue-item) that grabs an item

4条回答
  •  再見小時候
    2020-12-13 05:07

    (let [switch (atom true) ; a switch to stop workers
          workers (doall 
                    (repeatedly 20 ; 20 workers pulling and processing items from SQS
                      #(future (while @switch 
                                 (retrieve item from Amazon SQS and process)))))]
      (Thread/sleep 100000) ; arbitrary rule to decide when to stop ;-)
      (reset! switch false) ; stop !
      (doseq [worker workers] @worker)) ; waiting for all workers to be done
    

提交回复
热议问题