Objectives
In this week, I’m planning to do the following stuff:
- Work on the Vert.x Blueprint - Kue (Initial implementation)
- Learn more about event-driven and message system
Knowledge got
This week I’ve learned a lot!
- Clustered Verticles and how to interact with each other
- Vert.x Event Bus (send/recv and pub/sub)
- Vert.x Service Proxy
- More understanding about Redis(sorted set, list, pub/sub, transaction, etc)
- More understanding about asynchronous and reactive pattern(
Handler
/Future
)
Issues
How to implement priority?
I imitate Kue in Node.js: use sorted sets in Redis and mark the priority as the score(weight). Use zadd
to add a certain id of job and when necessary, use zpop
(implemented with transaction) to get a job with higher priority.
How to emit and receive events?
In Node.js, we could use EventEmitter
to emit and listen to events. And in Vert.x, we could make full use of EventBus
, which supports three kinds of pattern. For example, in Node.js we may write this:
1 | self.on('complete', fn); |
And in Vert.x we could write:
1 | // listen to an address |
Achievement
Refined the design of Vert.x Kue
Kue
: like theQueue
in Kue. We couldcreateJob
andprocess
the jobKueVerticle
: a verticle where theKueService
is registeredKueWorker
: a worker verticle that processes the jobKueService
: createKueWorker
and deploy itJob
: the job entity, contains numerous logic about job
The backend of Vert.x Kue is Redis.
Basic usage (design) of Vert.x Kue:
1 | // write this and then run with Vert.x Launcher in clustered mode |
Initial concept implementation of Vert.x Kue
See here: sczyh30/vertx-blueprint-job-queue