Sending java.lang.Object using EventBus

795 views
Skip to first unread message

Oren Shvalb

unread,
May 4, 2014, 5:20:20 AM5/4/14
to ve...@googlegroups.com
Hi,

I'm trying to send a Pojo class via EventBus.send(String, Object) 

and it fails with exception becasue the method:

static <U> BaseMessage<U> createMessage(boolean send, String address, U message)

doesn't have a check for "X instance of Object".

I'm using the latest Vertx core 2.1RC3


What am I doing wrong??

Jordan Halterman

unread,
May 4, 2014, 5:55:29 AM5/4/14
to ve...@googlegroups.com
The event bus only really supports the other-than-Object types defined in its interface (primitives and JsonObject, JsonArray, and Buffer). Other Java objects aren't supported because of the polyglot nature of Vert.x. The basic types the event bus supports are all supported by each language implementation. Sending other Java objects (checking instanceof Object and thus sending *all* objects) on the event bus would complicate things if, for instance, the receiving side is a Javascript verticle.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oren Shvalb

unread,
May 4, 2014, 7:10:57 AM5/4/14
to ve...@googlegroups.com
Ok, so why does it appear in the API of EventBus ??

EventBussend(java.lang.String address, java.lang.Object message)

Jordan Halterman

unread,
May 4, 2014, 7:29:48 AM5/4/14
to ve...@googlegroups.com
I'm sure Tim can speak to that. I would suppose that it might be intended for calls from some of the various language implementations (depending on how they handle Java types internally) which wrap the Java API, but don't quote me on that :-)

Nevertheless, Java objects other than those I mentioned are not intended to be supported by the event bus for the reasons I mentioned.
--

Jordan Halterman

unread,
May 4, 2014, 7:43:28 AM5/4/14
to ve...@googlegroups.com
One thing about the Vert.x API is that it's designed to support a lot of different JVM-based language implementations. But the event bus supports only those specific types. What you're seeing is not a bug, it is intentional. Just check out the Message implementations and you'll see ObjectMessage is notably missing from the bunch:


Fortunately, I think the event bus is the only area of the API that I can think of where the implementation doesn't seem to match the interface.

On May 4, 2014, at 4:10 AM, Oren Shvalb <oren....@gmail.com> wrote:

--

Jordan Halterman

unread,
May 4, 2014, 7:44:43 AM5/4/14
to ve...@googlegroups.com
Sorry, I should have linked to this as a better example of how the event bus handles message types:


On May 4, 2014, at 4:10 AM, Oren Shvalb <oren....@gmail.com> wrote:

--

dexter31

unread,
May 4, 2014, 9:30:41 AM5/4/14
to ve...@googlegroups.com
Just tried this. I believe its a documentation issue and as Jordan pointed out, the ObjectMessage is indeed missing. I would consider serialization as one of the primary reasons why this was maybe omitted. Im no expert here though.

Jordan Halterman

unread,
May 4, 2014, 10:26:39 PM5/4/14
to ve...@googlegroups.com
I'll look at the docs and see if maybe this can be better clarified - perhaps in the API manual or on the send(Object message) method documentation in particular.
--

Stream Liu

unread,
May 4, 2014, 11:43:50 PM5/4/14
to ve...@googlegroups.com

Hi.

i extract the lib of own project which provide a trick could send pojo
over eventBus to other veticle. this is project[1]. you could get more
information, from test.

[1]https://github.com/stream1984/rxBus

Oren Shvalb

unread,
May 5, 2014, 12:45:51 AM5/5/14
to ve...@googlegroups.com
Thank you for all the people that have answered by question....

It would be a "better world" if POJO classes could be transferred via EventBus, I do understand the problematic issues it creates - but still it would make things much easier...

perhaps there could be a special interface\implementation a specially for JAVA based modules that could pass POJOs over EventBus or something like that.... maybe for Vert.x 3.0  ... :-)

Stream.liu : I will try your implementation to see whether it works for me, Thank you!



On Sunday, May 4, 2014 12:20:20 PM UTC+3, Oren Shvalb wrote:

Jordan Halterman

unread,
May 5, 2014, 1:26:33 AM5/5/14
to ve...@googlegroups.com
I think this has be pretty well roundly rejected by Tim even for Vert.x 3 (see the json serialization thread going on right now), and I agree with him. Obviously it's possible if both the sending and receiving side are Java verticles, but there's no way to impose such a restriction. Supporting arbitrary Java objects on the event bus would eliminate one of Vert.x's primary features by forcing both sides to be implemented in Java, and that's something Vert.x is not prepared to give up. You may argue that that should be up to the user, and that's a valid point. But the goal is to provide the same feature set in all supported languages. 

There is a lot of discussion going on about Vert.x 3's event bus and serialization, so feel free to weigh in. It may be possible that arbitrary objects can be supported by the event bus, but I think that would be only *if all languages support deserialization and usage* of said objects - perhaps by providing a custom serialization API in each language - but that may not even happen.

I think you share your experience, concerns, and suggestions on the serialization thread. But keep in mind the reasons why it isn't currently supported. Tim and the others will surely weigh in.

Jordan Halterman
--
Reply all
Reply to author
Forward
0 new messages