Problems by setting up a MongoDB with vertx3

724 views
Skip to first unread message

Sandra Kriemann

unread,
Jul 28, 2015, 6:33:43 AM7/28/15
to vert.x
Hello Experts,

I am still working on my project for university. You can find the project here: https://github.com/SandraKriemann/foodrater

I want to store the data I am getting via Rest inside a MongoDB, but when I am trying to access the mongodb by running the fat jar I am getting this Exception:

Jul 28, 2015 12:11:02 PM io.vertx.core.Starter

INFORMATION: Succeeded in deploying verticle

Jul 28, 2015 12:11:03 PM com.mongodb.diagnostics.logging.JULLogger log

INFORMATION: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}

Jul 28, 2015 12:11:03 PM com.mongodb.diagnostics.logging.JULLogger log

INFORMATION: Exception in monitor thread while connecting to server localhost:27017

com.mongodb.MongoInternalException: Opening the AsynchronousSocketChannelStream failed

at com.mongodb.connection.FutureAsyncCompletionHandler.get(FutureAsyncCompletionHandler.java:65)

at com.mongodb.connection.FutureAsyncCompletionHandler.getOpen(FutureAsyncCompletionHandler.java:43)

at com.mongodb.connection.AsynchronousSocketChannelStream.open(AsynchronousSocketChannelStream.java:60)

at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)

at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)

at java.lang.Thread.run(Thread.java:745)

Caused by: com.mongodb.MongoSocketOpenException: Exception opening socket

at com.mongodb.connection.AsynchronousSocketChannelStream$1.failed(AsynchronousSocketChannelStream.java:86)

at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:128)

at sun.nio.ch.Invoker$2.run(Invoker.java:218)

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)

... 1 more

Caused by: java.net.ConnectException: Connection refused

at sun.nio.ch.UnixAsynchronousSocketChannelImpl.checkConnect(Native Method)

at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:252)

at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:198)

at sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213)

at sun.nio.ch.KQueuePort$EventHandlerTask.run(KQueuePort.java:301)

... 1 more



I found this documentation http://vertx.io/docs/vertx-mongo-client/java/ and examples: https://github.com/halber/TestVertx3MongoDB/blob/master/src/main/java/App.java

http://github.com/vert-x3/vertx-examples/blob/master/web-examples/src/main/java/io/vertx/example/web/mongo/Server.java and I implemented the logging.


When I try to store data into the db I get this:

INFORMATION: No server chosen by PrimaryServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoInternalException: Opening the AsynchronousSocketChannelStream failed}, caused by {com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]}. Waiting for 30000 ms before timing out



So, what do I miss? Is there a way, how I can see, what is inside of my mongodb? I installed the plugin for intellij, but as I am not setting up the monodb correctly I can't see there anything.


Thank you for helping.
Sandra

Ingo Hoffmann

unread,
Jul 28, 2015, 6:55:57 AM7/28/15
to ve...@googlegroups.com
Hi,

It does look like the MongoDB server is either not running or, if running, you are connecting to a different port instead what was configured.

Cheers

--
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/de274c6b-4076-42c4-9c86-4afd26713e40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sandra Kriemann

unread,
Jul 28, 2015, 7:28:37 AM7/28/15
to vert.x, in...@hoffmann.cx
Hello Ingo,

thank your for your investigation.

That's how the code looks like:
public static final String ADDRESS = "mongodb-persistor";
public static final String DEFAULT_MONGODB_CONFIG
= "{"
+ " \"address\": \"" + ADDRESS + "\","
+ " \"host\": \"localhost\","
+ " \"port\": 27017,"
+ " \"db_name\": \"bs\","
+ " \"useObjectId\" : true"
+ "}";
MongoClient mongo;


@Override
public void start() {
mongo = MongoClient.createShared(vertx, new JsonObject(DEFAULT_MONGODB_CONFIG));
LOGGER.info("MongoClient is started with this config: " + new JsonObject(DEFAULT_MONGODB_CONFIG).encodePrettily());

And I am getting the exception, when he tries to createShared. Am I using it correctly or is there something missing?


Best
Sandra

Ingo Hoffmann

unread,
Jul 28, 2015, 7:46:17 AM7/28/15
to vert.x
Hi,

Check if MongoDB is running on port 27017. Try using netstat -n and look through the LISTEN connections.

Cheers

Sandra Kriemann

unread,
Jul 28, 2015, 8:07:54 AM7/28/15
to vert.x, in...@hoffmann.cx
As expected, there is no mongodb and nothing running on port 27017 :(

Is my configuration wrong or the way I am trying to access it?


Thank you so much

Sandra



Ingo Hoffmann

unread,
Jul 28, 2015, 8:15:16 AM7/28/15
to vert.x
Hi,

Try installing or, if already installed, run MongoDB before executing your Vert.x application. Since you seem to be running on OS X, here are the instructions: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

Cheers
Reply all
Reply to author
Forward
0 new messages