GithubHelp home page GithubHelp logo

ajmwagar / orizuru Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rubik/orizuru

0.0 2.0 0.0 261 KB

A reliable, scalable and flexible Redis message queue for Rust.

License: ISC License

Rust 98.84% Makefile 0.45% Shell 0.71%

orizuru's Introduction

Orizuru logo

Orizuru (折鶴)

A reliable, scalable and flexible Redis message queue for Rust.

Build Code Coverage Downloads (all time) ISC License

Design

Queues are backed by Redis lists and as such they support multiple producers and consumers:

  • To publish a message to a source queue, a producer runs an LPUSH command;
  • Periodically, a consumer fetches messages from the source queue and pushes them to its own processing queue. Then, it may choose to acknowledge them or reject them. Acknowledged messages are removed from the processing queue, while rejected messages are moved to the unack queue.

Each queue can have an unlimited number of concurrent consumers. Consumers fetch messages with the BRPOPLPUSH command, that blocks until at least one message is available on the source queue, and then pushes it to its processing queue. This operation is atomic, which means that only one consumer can receive the message even if there are multiple consumers fetching messages from the source queue.

Optionally, unacknowledged messages can be collected by the garbage collector that periodically returns them to the source queue. If the garbage collector does not run, unack queues are essentially dead-letter queues and could grow without bound.

Orizuru architecture

Simplicity

In line with Rust's philosophy of not not picking a specific implementation strategy, Orizuru is designed with simplicity in mind. This informs both the public API, which is minimal, and the implementation. All the functionality is implemented as a library, so that the user is free to integrate it in their architecture however they wish.

API

Producer::push<T: MessageEncodable>(message: T) -> Option<RedisResult<i32>>
Push a message onto a source queue.

Consumer::next<T: MessageDecodable>() -> Option<RedisResult<MessageGuard<T>>>
Fetch the next message from the queue. This method blocks and waits until a new message is available.

MessageGuard::ack() -> RedisResult<Value>
Acknowledge the message and remove it from the processing queue.

MessageGuard::reject() -> RedisResult<Value>
Reject the message and push it from the processing queue to the unack queue.

MessageGuard::push(push_queue_name: String) -> RedisResult<Value>
Remove the message from the processing queue and push it to the specified queue. It can be used to implement retries.

The traits MessageEncodable and MessageDecodable ensure that the message can be serialized and deserialized to/from Redis. They are implemented by default for all the objects that implements the Serialize and Deserialized traits from the serde crate, by using the Msgpack encoding. This is a binary encoding analogous to JSON. It was chosen because of the encoding and decoding speed and space efficiency over JSON.

Usage patterns

Orizuru is a message queue, but it can be specialized into a job queue, when the messages represent job payloads. However, the acknowledgement pattern differs between the two. In the case of a generic message queue, messages are acknowledged as soon as they are received, as that is what matters. In the case of a job queue, on the other hand, messages are acknowledged after the job has been executed (maybe even successfully). That protects the jobs from random failures or worker crashes. In both cases the presence of a garbage collector is essential to ensure that the deliveries/executions are retried.

License

ISC

Logo image based on the one made by Smashicons for www.flaticon.com.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.