Skip to content

SpokaneTech/go-meetup-worker-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NATS Queues


Two types of queue workers

  1. Standard queue with DLQ
  2. Long running work queue

Standard queue with DLQ

  • Similar to SQS style work queues
  • Very simple to implement DLQ as it is just built into NATS
  • Length of work must be known and short. In this example 5 seconds, 10 seconds, and 15 seconds
    • Although since each consumer configures it's own timeouts you can probably have some interesting patterns

Example


Long running work queue

  • Instead of receiving work from a queue workers lobby for work
  • That work is expected to run for a very long time but might be terminated at any time
    • if work is terminated it should be available to be reclaimed at a later date by another worker

Long running work queue implementation

  • Instead of using a queue, use a key value store

    • Redis has something available for this called a redlock/redsync
    • But we can simply implement it in NATS as well
  • In NATS we use a separate KV bucket with a TTL

  • When a worker wants to claim some work it attempts to write a lock to the KV bucket

  • The worker updates the lock every X seconds to keep the lock owned

  • If the worker fails to update the lock it will be deleted by the TTL and available to reclaim

Example

About

A demonstration of a worker queue and worker claims roster using NATS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages