在“本地"(java,单个 jvm)使用 Vert.x eventbus 时是否可以避免序列化? [英] Is it possible to avoid serialization when using the Vert.x eventbus 'locally' (java, single jvm)?

查看:20
本文介绍了在“本地"(java,单个 jvm)使用 Vert.x eventbus 时是否可以避免序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是:

  • 单个 JVM
  • 仅限 Java(我不需要会多种语言)
  • 我不想支付序列化成本来在总线上发布不可变事件(发布对 java 对象的引用会起作用).

我了解 vert.x 事件总线的范围比我的用例要广泛得多.

I understand the scope of the vert.x event bus is much broader than my use case.

我想到了一种类似于 akka 的行为:当你去分布式时,你必须为你的消息提供序列化,如果你保持本地引用被传递.

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.

有什么东西可以让我在 Vert.x 中做到这一点吗?

Is there anything that would allow me to do that in Vert.x?

推荐答案

Vert.x 已经有了这样的优化.当发送到同一个 JVM 时,对象不会被序列化或反序列化.

Vert.x already has such an optimization. When sending to the same JVM, objects won't get serialized or deserialized.

你可以在这里看到实际的代码:https://github.com/eclipse/vert.x/blob/master/src/main/java/io/vertx/core/eventbus/impl/EventBusImpl.java#L372

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

当你实现你的 MessageCodec 时,你实际上有两种方法:decodeFromWire()transform().您只能使用最幼稚的方法实现转换:

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

这篇关于在“本地"(java,单个 jvm)使用 Vert.x eventbus 时是否可以避免序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆