1
votes

Has anyone tried to use MongoDB Atlas Database as a service (https://www.mongodb.com) with Vertx?

I've tried to connect but I keep getting the following error:

INFO: Exception in monitor thread while connecting to server socie-shard-00-01-zeymc.mongodb.net:27017
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
    at com.mongodb.connection.AsynchronousSocketChannelStream$BasicCompletionHandler.completed(AsynchronousSocketChannelStream.java:215)
    at com.mongodb.connection.AsynchronousSocketChannelStream$BasicCompletionHandler.completed(AsynchronousSocketChannelStream.java:201)
    at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
    at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:281)
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ReadTask.completed(WindowsAsynchronousSocketChannelImpl.java:579)
    at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:397)
    at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

I used the following:

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-mongo-client</artifactId>
    <version>3.5.0</version>
</dependency>

Than I tried to used their Java Mongo driver:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.6.0</version>
</dependency>

This works. Only this takes a big rewrite on all my queries. And I'm not sure if this is a good driver in combination with Vertx.

Does anyone know how to fix the error above or does anyone know if it's safe to use the org.mongodb java driver.

Many thanks in advance!

My solution

Thanks to Daniel, I managed to get it working with the vertx-mongo-client!

I added to my Json config

config.put("ssl", true);

And I added the following line before creating the MongoClient.

System.setProperty("org.mongodb.async.type", "netty");
1
Have you checked the minimum driver requirement for their Database as a Service offering? vertx-mongo-client comes with 3.4.1 by default. It works with 3.5.0 but not yet with 3.6.0 (see issue #108 on GitHub). - tsegismont
They have two (3.6 and 3.4). I'm using 3.4 database - Berend Menninga
Would you mind to file an issue on GitHub so we can track the problem and solutions? Thanks github.com/vert-x3/vertx-mongo-client/issues/new - tsegismont

1 Answers

0
votes

Had a similar problem a while ago, but got it working with the official vertx mongo client. I only had to be sure to provide all the connection info. Example:

{
hosts: [
    {
        host: "xpto-shard-00-00-aaa.mongodb.net",
        port: 27017
    },
    {
        host: "xpto-shard-00-01-aaa.mongodb.net",
        port: 27017
    },
    {
        host: "xpto-shard-00-02-aaa.mongodb.net",
        port: 27017
    }
],
replicaSet: "xpto-shard-0",
db_name: "db_name",
username: "username",
password: "password",
ssl: true,
authSource: "admin",
maxPoolSize: 30,
minPoolSize: 5,
waitQueueMultiple : 100

}

Also, I had to be sure to set a system property:

var System = Java.type("java.lang.System");
System.setProperty("org.mongodb.async.type", "netty");

(This verticle is in Javascript but it's pretty much the same in Java)