MongoService and multiple instances

107 views
Skip to first unread message

Jan De Cooman

unread,
Jul 17, 2015, 5:44:52 AM7/17/15
to ve...@googlegroups.com

Hi 

I'm experiencing problems with the MongoService class when I'm running more than one instance. I try to page through a MongoDB collection with paging. This is nothing new and was supported in Vertx2. Now, I have the same mechanism. But, when depending on the instance who is responding to the message, I get a JsonObject or a LinkedHashMap. This is of course very anyoning, and maybe a bug? With one instance, I always get the JsonObjects. With more instances, I get mixed results.

Is it a bug or a feature?




            // mongodb being the MongoService eventbus proxy.
            mongodb.findWithOptions(
                    MONGO_COLLECTION,
                    new JsonObject(),
                    new FindOptions().setSkip(skip).setLimit(PAGE_SIZE), e -> {

                        // Normally seen, I have a List<JsonObject> here. But I get ClassCastExceptions with more instances.
                        List results = e.result();

                        // index results
                        results.stream().forEach((o) -> {
                            if (o instanceof JsonObject) {
                                System.out.println("A JSONOBJECT");
                            } else if (o instanceof LinkedHashMap) {
                                System.out.println("HEY I GOT A MAP FROM ANOTHER INSTANCE");
                            }
                        });
                    });


Greetings
Jan

Jan De Cooman

unread,
Aug 4, 2015, 7:25:37 AM8/4/15
to vert.x
Did somebody experience the same issue up til now?

Michel Guillet

unread,
Oct 28, 2015, 1:19:35 PM10/28/15
to ve...@googlegroups.com
Almost 3 month after…

Yes! I have got the exact same issue.

I think this is coming from the fact that the event bus proxy generation doesn’t support generics (because of the lack of real generics in the JVM ?).

The findWithOptions method from the mongo client is supposed to return a list of JsonObject (so List<JsonObject>). And it does, but the message serialization losses the List<JsonObject> information and the proxy helper don’t know what to deserialize. (List<Map> or List<JsonObject> ?)

This is related to an issue I’ve talked about https://groups.google.com/d/topic/vertx/suRnQFnyybg/discussion

Long story short, if you use the vertx-mongo-service you’ll get this issue quite quickly. Loose the service and use one client per vertx instance and you’ll be fine.

I’m willing to help on this issue (by creating a test case or help fixing it). But I think this is a tricky one and could cause some issue with other vert.x supported languages.

Anyone in the core team to comment on that?

Thanks,

Michel

> On 04 Aug 2015, at 13:25, Jan De Cooman <jan.de...@neofonie.de> wrote:
>
> Did somebody experience the same issue up til now?
>
> --
> 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.
> Visit this group at http://groups.google.com/group/vertx.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/f878ab4f-efdc-4d89-b0e5-53576579bbbf%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Michel Guillet

unread,
Oct 29, 2015, 6:31:36 AM10/29/15
to ve...@googlegroups.com
Ok, I got a bit carried away with generics, this Mongo issue a nothing to do with generics.

I think the issue come the fact that when using local service the message payload is not serialized but copied (JsonArrayMessageCodec.transform). When using a remote service, the message payload is fully serialized and uses JsonArrayMessageCodec.decodeFromWire.

Hence:
JsonArray obj = new JsonArray();
obj.add(new JsonObject());
obj.add(new JsonObject());
obj.add(new JsonObject());

will be copied and keep instances of JsonObject within the array whereas - when serialized and deserialized - we will get Map instances instead of JsonObject ones.

Then you get a cast exception tried to convert these Map into JsonObject.

I think the fix need to be done in the code generation template of vertx-service-proxy.

I’ll try to see if I find a nice way of fixing it and propose a PR if I can.

Michel

Julien Viet

unread,
Oct 29, 2015, 6:47:25 AM10/29/15
to ve...@googlegroups.com, Michel Guillet
thanks, yes we have been having issues with nested Map in JsonObject for a while

-- 
Julien Viet
www.julienviet.com

Michel Guillet

unread,
Oct 29, 2015, 7:24:57 AM10/29/15
to Julien Viet, ve...@googlegroups.com
I’m working on a fix, I’ll create a PR on vertx-service-proxy when I’m done.

It might not be pretty though…

Michel

Michel Guillet

unread,
Oct 29, 2015, 10:06:10 AM10/29/15
to ve...@googlegroups.com
Julien,

You can find my attempt to fix this issue here: https://github.com/vert-x3/vertx-service-proxy/pull/29

Michel

David Bush

unread,
Nov 16, 2015, 12:07:01 PM11/16/15
to vert.x
Hi Michel,

I'm glad you found the problem. It's been killing me over the last few days. Is your fork of vertx-service-proxy usable? 

I hope they can get the PR merged quickly.

Michel Guillet

unread,
Nov 16, 2015, 12:17:48 PM11/16/15
to ve...@googlegroups.com
It passes the test so it should be fine but it hasn’t got reviewed yet.

I’m sure you can create a JAR snapshot out of it.

In my code I decided not to use it but to use the workaround above the mongo service as I was only facing the issue in one place.

Let me know if you have any issue with the fix.

Cheers,

Michel

--
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.
Visit this group at http://groups.google.com/group/vertx.

Michel Guillet

unread,
Nov 17, 2015, 4:28:37 AM11/17/15
to ve...@googlegroups.com
Any chance we can see https://github.com/vert-x3/vertx-service-proxy/pull/29 in 3.2?

Or something else fixing the issue ?

Thanks, let me know if you need me.

Michel
Reply all
Reply to author
Forward
0 new messages