Hey all, I'm trying out vert.x and so far, I like it a lot. I'm just writing some test applications in java... and like most applications, I have a verticle to fetch some data from a database and sending back the response, in this case the db being postgresql. In the most common approach, data from the db is mapped to java classes.
However, since (1) json is the prefered format for communicating over the vert.x event bus and (2) postgresql 9.2 comes with native json support, I just want to skip the orm step. This could avoid a whole bunch of hardly used model classes, which are basically only used to construct a JsonObject afterwards, this means more cpu and memory usage.
Thus, I'm fetching the data from the db returns a json-string, so I'm actually reading a String result in java. There are still two possibilities here: or I send the (json-formatted) String as is over the event bus or I turn the String into a JsonObject (or JsonArray) before sending over the event bus. In the latter case, there is some (unnecessary) overhead for object creation, serialization and deserialization.
What would be the best strategy here? The question might also be: is there any advantage of constructing a JsonObject on the server side before sending the data back to the client? My gut feeling points me to "just send the string and don't bother about creating a JsonObject". I just want to be sure I'm not missing something crucial.
Just for clarity: no extra data handling is necessary after fetching it
from the database (or if data handling is necessary, I might choose to handle it on the client). I just want to fetch data and send it to the client. So the
client (javascript) have something like:
eventbus.send("fetchdata", somerequestdata, function(replydata) {
doSomethingWithTheDataProbablyShowIt() })On the server side I have something like (simplified):
public class FetchData extends BusModBase {
@Override
public void start() {
vertx.eventBus().registerHandler("fetchdata", new Handler<Message<String>>(){
public void handle(Message<JsonObject> requestData) {
String fetchedData = fetchDataFromPostgresql(requestData);
// convert fetchedData to json or not?
requestData.reply(fetchedData);
}
});
}
[...]
}