-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@robojs/mq - Plugin for persistent message queue. #306
Comments
Hi @Pkmmte! I'd be interested in looking into this feature. If I understand correctly, you'd ideally like to use some message queue system that would use Flashcore as the tool to persist the messages, correct? You've reference BullMQ, which I'm looking into. If we decide to use that tool, this package could be a wrapper around BullMQ, but with the ability to persist the messages sent to it. If that's the case, I'm curious to know how you'd like to be able to retrieve the persisted messages. Would that be through using Flashcore directly? If you could briefly describe use cases for this, that would be amazing. Thanks!! |
Hi @branberry and thanks for your interest!
Yup, sounds about right! However, after looking more into BullMQ, I would like to retract my earlier comment and suggest something else instead, like Packages like
Also yes. Ideally, this would take place automatically when Robo projects start using the |
@branberry I've updated this issue's description to be more detailed. You can think of the above spec as a strong recommendation rather than strict requirement. Feel free to improve upon it or suggest an alternative API syntax as long as it avoids OOP for consistency with the rest of our plugins. |
Hey @Pkmmte, thank you for the thorough response! I appreciate the insights into what you're looking for. I think I should be equipped with enough info to get started. Thanks again! |
Description
A plugin to provide a dead-simple, fully functional message queue API for Robo.js projects without relying on heavyweight external services or binaries, and without requiring separate worker processes. By default, it ships with an in-memory queue engine (optionally persisting messages). Users may easily swap out this engine with a custom one (e.g., Redis-based) using a single plugin option,
engine
.This plugin aims to offer:
MqEngine
.Goals
Lightweight, Minimal Footprint
Functional + Subscription API
subscribe
) to continuously handle incoming messages without manual polling or intervals.Custom Engine Support
MqEngine
abstract class.Message Acknowledgements
fail
is called or the engine times out.Type-Safe Payloads
API Overview
1. Plugin Options
engine
: If not provided, uses a default in-memory engine (optionally with internal persistence).subscribe
will rely on repeateddequeue
calls or an event-based mechanism within the engine to pull messages.concurrency
: Number of in-flight messages we’ll process at once for a given subscription.2. Functional API
enqueue
: Add a new message to the specified queue.subscribe
: Continuously listen for incoming messages onqueueName
and callonMessage
each time.concurrency
option to avoid overloading your app.ack
: Acknowledge successful processing of a message, removing it from the queue.fail
: Indicate a failure, allowing the engine to requeue or discard the message based on your configuration.3. Type-Safe Payloads
You can specify the payload type when you subscribe or enqueue:
4. Concurrency Control in
subscribe
concurrency
determines how many messages can be processed simultaneously for a given queue subscription. If concurrency is set to 1, each message must finish processing (viaack
orfail
) before the next message is delivered.5. Same-Context Runtime
No separate workers or extra processes needed. Everything runs in the same environment as the Robo.js project, making setup and debugging simpler.
6. Persistence (Optional)
7. Example: Custom Redis Engine
Below is a simplified example demonstrating how a Redis-based engine might be implemented. This shows how you can override the default in-memory queue by extending the
MqEngine
class.Usage
Plugin config:
Start event usage:
The
@robojs/mq
plugin provides:enqueue
,subscribe
,ack
,fail
subscribe
.MqEngine
interface to seamlessly switch to more robust or remote solutions (Redis, RabbitMQ, etc.).The text was updated successfully, but these errors were encountered: