Is it possible to avoid serialization when using the Vert.x eventbus 'locally' (java, single jvm)?

孤人 提交于 2020-12-30 06:48:07

问题


My case is:

  • single JVM
  • Java only (i don't need to be polyglot)
  • I don't want to pay serialization costs to publish an immutable event on the bus (publishing the reference to the java object would work).

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?


回答1:


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;
}


来源:https://stackoverflow.com/questions/51377833/is-it-possible-to-avoid-serialization-when-using-the-vert-x-eventbus-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!