My case is:
I understand the scope of the vert.x event bus is much broader than my use case.
I had in mind a behaviour similar to akka: when you go distributed you have to provide serialization for your messages, if you stay local references get passed.
Is there anything that would allow me to do that in Vert.x?
Java serialization enables writing Java objects to file system for permanent storage or on network to transfer to other applications. Serialization in Java is achieved with Serializable interface. Java Serializable interface guarantees the ability to serialize the objects.
There are at least two options of using the EventBus in Vertx: I use the Eventbus methods provided by Vertx to call functions residing on another Verticle. The upside here is that I can use Codecs to pass parameters over the Eventbus.
Oracle is planning to eventually remove Java serialization as part of Project Amber. However, this may take a while, and it’s unlikely to be fixed in previous versions. Therefore, it is wise to avoid Java serialization as much as possible.
If we note output, subclass was Serializable (as subclass always inherits all features from its parent class), for avoiding Serialization in sub-class we defined writeObject () method and throwed NotSerializableException() from there. If member of class does not implement Serializable interface - than NotSerializableException is thrown.
Vert.x already has such an optimization. When sending to the same JVM, objects won't get serialized or deserialized.
You can see the actual code here: https://github.com/eclipse/vert.x/blob/master/src/main/java/io/vertx/core/eventbus/impl/EventBusImpl.java#L372
When you implement your MessageCodec
, you actually have two methods: decodeFromWire()
and transform()
. You can implement only transform with the most naive approach:
@Override
public Object transform(Object o) {
return o;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With