Sending Java objects over event bus

811 views
Skip to first unread message

Eranga Samararathna

unread,
Jun 30, 2014, 8:10:55 AM6/30/14
to ve...@googlegroups.com
Hi,

Few questions in my mind.

1.) Is it possible to send Java objects over vert.x event bus?
2.) What is the serialization mechanism used in vert.x ? Java standard serialization ??

If vert.x use Java standard serialization;   Any idea about the effort need to convert that to something else like Kryo

Thanks

Era.

Nick Scavelli

unread,
Jun 30, 2014, 9:55:42 AM6/30/14
to ve...@googlegroups.com
Answers inline


On Monday, June 30, 2014 8:10:55 AM UTC-4, Eranga Samararathna wrote:
Hi,

Few questions in my mind.

1.) Is it possible to send Java objects over vert.x event bus?

Not at the moment. Something we're working on for 3.0
 
2.) What is the serialization mechanism used in vert.x ? Java standard serialization ??

No, it's manual. Since we know what types are being sent (String, Integer, Double, JsonObject) we just convert them down to bytes.

Jamie B

unread,
Jun 30, 2014, 11:38:08 AM6/30/14
to ve...@googlegroups.com
Perhaps simply exposing support for Hazelcast's Portable serialisation? This would allow serialisation via any means desired by the developer (as well as out-the-box options).

qsys

unread,
Jul 1, 2014, 4:14:24 AM7/1/14
to ve...@googlegroups.com
Well, actually: yes. Serialize to byte array and you're set. I'm using FST serialization in most cases, json or json array serialization in other cases.
This is how it more or less looks like for FST serialization (exceptions not properly handled):

   private final FSTConfiguration fstConf = FSTConfiguration.createDefaultConfiguration();
 
   
@Override
   
public void handle(final Message<String> message) {
     
[...]
     
final ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
     
final FSTObjectOutput out = this.fstConf.getObjectOutput(arrayOut);
     
try {
         
out.writeObject(someObject, SomeObject.class);
         
out.flush();
     
} catch (final IOException e) {
         e
.printStackTrace();
     
}
      message
.reply(out.getBuffer());
     
try {
         arrayOut
.close();
     
} catch (final IOException e) {
         e
.printStackTrace();
     
}
   
}

and:

       [...]
       
new Handler<Message<byte[]>>() {
           
@Override
           
public void handle(final Message<byte[]> event) {
               
final ByteArrayInputStream byteArray = new ByteArrayInputStream(event.body());
               
try {
                 
final FSTObjectInput in = SomeHandler.this.fstConf.getObjectInput(byteArray);
                 
final T result = ((T) in.readObject());
                  byteArray
.close();
               
} catch (final IOException | ClassNotFoundException | InterruptedException e) {
                  e
.printStackTrace();
               
}
           
}
         
});
     
[...]





Op maandag 30 juni 2014 14:10:55 UTC+2 schreef Eranga Samararathna:

Eranga Samararathna

unread,
Jul 1, 2014, 6:05:01 AM7/1/14
to ve...@googlegroups.com
Thanks qsys. How do you send FST serialized object over event bus ? as a vert.x buffer ??

qsys

unread,
Jul 1, 2014, 6:52:52 AM7/1/14
to ve...@googlegroups.com
So far, only as a byte[], for example, this line converts the serialized object to a byte array and sends the byte array back to the 'requestor':
message.reply(out.getBuffer())

On the client side, I receive a byte[]:
new Handler<Message<byte[]>>() {...}

All I do in the 'handle'-method, is reading the object to 'result'. It's embedded inside some other stuff, hence the generic T. But I suppose you get the idea... You can use kryo (or any other serialization) if you want. All you need is a byte array...

greetz, qsys



Op dinsdag 1 juli 2014 12:05:01 UTC+2 schreef Eranga Samararathna:

Eranga Samararathna

unread,
Jul 2, 2014, 9:05:41 AM7/2/14
to ve...@googlegroups.com
Thanks qsys. I'll give a try.

On Monday, June 30, 2014 5:40:55 PM UTC+5:30, Eranga Samararathna wrote:
Reply all
Reply to author
Forward
0 new messages