I am using vertx3
I need to use redis in order to set and get values.(Redis might be changed to something else in the future)
Iam looking for best practice design for my implementation.
I am working on vertx cluster and I need to retrieve a messages via the eventbus extract the message and insert into Redis.
In the other hand I can get requests via web and also extract the messages and insert them into redis
Two options:
Should I have a "redis-verticle" that get the messages via the bus and write them.
Should I create a "Listener verticle" that will hold DAO which will hold RedisRepo object which will write them.
I will also be able to handle the web calls and hold this DAO object
If I was on spring-app I would create a DAO which holds RedisRepo and Inject it into my service layer but here we got the eventbus so I am not sure.
(btw the redis datasource me be changed to something else so I gotta think about generic wrappers)
1.
public class RedisRepoVerticle extends AbstractVerticle {
...
public void start() {
client = new RedisClient("localhost", 6379);
connection = client.connect();
...
vertx.eventBus().consumer("redis-operation", (handler) -> {
{
JsonObject msg = new JsonObject(handler.body().toString());
//write straight to Redis
}
});
}
2.
public class RedisMessageListener extends AbstractVerticle {
DatasourceDAO datasource
...
public void start() {
client = new RedisClient("localhost", 6379);
connection = client.connect();
...
vertx.eventBus().consumer("redis-operation", (handler) -> {
{
JsonObject msg = new JsonObject(handler.body().toString());
datasourceDAO.writeToRedis(..);
}
});
}
//datasourceDAO will hold RedisRepo object
If I take the second option should I start maintain singletons? I dont want to duplicate my daos which will duplicate my redisrepo's classes