amokan / off_broadway_redis

A Broadway producer for Redis lists
MIT License
25 stars 7 forks source link

OffBroadway.Redis

Build Status Hex.pm

An opinionated Redis connector for Broadway to process work from a Redis list structure.

Documentation can be found at https://hexdocs.pm/off_broadway_redis.

This project provides:

What is opinionated about this library?

Because Redis lists do not support the concept of acknowledgements, this project utilizes the RPOPLPUSH command available in Redis to atomically pop an item from the list while moving the item to a 'working' or 'processing' list for a later pseudo-acknowledgement using the LREM command.

This idea follows the blueprint of the Reliable Queue pattern outlined in the Redis documentation found here.

Because RPOPLPUSH is used, the other assumption is that the head of your list will be on the right side, so you will likely want to push work into your list using LPUSH (for FIFO processing). If you want to prioritize an item to be processed next, you could push that to the right (head) by using a RPUSH.

Redis Client

The default Redis client uses the Redix library. See that project for other features.

I have not attempted to use any other Redis libraries in the community at this point. I expect there may need to be changes made to this producer to accomodate others.

Caveats


Installation

Add :off_broadway_redis to the list of dependencies in mix.exs:

def deps do
  [
    {:off_broadway_redis, "~> 0.4.3"}
  ]
end

Usage

Configure Broadway with one or more producers using OffBroadway.Redis.Producer:

Broadway.start_link(MyBroadway,
  name: MyBroadway,
  producers: [
    default: [
      module: {
        OffBroadway.Redis.Producer,
        redis_instance: :some_redis_instance,
        list_name: "some_list",
        working_list_name: "some_list_processing"
      }
    ]
  ]
)

Other Info

This library was created using the Broadway Custom Producers documentation for reference. I would encourage you to view that as well as the Broadway Architecture documentation for more information.


License

MIT License

See the license file for details.