Deploy multiple verticles in a module

2,857 views
Skip to first unread message

Angelo K H

unread,
Aug 20, 2013, 4:33:39 PM8/20/13
to ve...@googlegroups.com

How do I deploy these 2 verticles in a module?

mod.json
{
 
"main": "EchoServer.java"
 
"main": "HelloWorldServer.java"
}



public class EchoServer extends Verticle {


 
public void start() {
    vertx
.createNetServer().connectHandler(new Handler<NetSocket>() {
     
public void handle(final NetSocket socket) {
       
Pump.createPump(socket, socket).start();
     
}
   
}).listen(1234);
 
}
}



public class HelloWorldServer extends Verticle {


 
public void start() {
    vertx
.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
     
public void handle(HttpServerRequest req) {
        req
.response().headers().set("Content-Type", "text/plain");
        req
.response().end("Hello World");
     
}
   
}).listen(8080);
 
}
}

Joern Bernhardt

unread,
Aug 20, 2013, 4:44:42 PM8/20/13
to ve...@googlegroups.com
Hi Angelo,

just use one "main": "Starter.java"

and in its public void start() method, use container.deployVerticle() two times, to start each Verticle.

HTH,
Joern

Angelo K H

unread,
Aug 20, 2013, 6:36:49 PM8/20/13
to ve...@googlegroups.com

I got ClassNotFoundException after following your steps. Do I miss anything?

$ vertx runmod io.vertx~simple-source-mod~1.0

Exception in Java verticle
java
.lang.ClassNotFoundException: HelloWorldServer


Exception in Java verticle
java
.lang.ClassNotFoundException: EchoServer

Here is the content of the folder:

$ ls -l mods/io.vertx~simple-source-mod~1.0

SimpleServer.java
EchoServer.java
HelloWorldServer.java
mod
.json


SimpleServer.java

public class SimpleServer extends Verticle {
 
public void start() {
  container
.deployVerticle("EchoServer");
  container
.deployVerticle("HelloWorldServer");
 
}
}

Joern Bernhardt

unread,
Aug 20, 2013, 6:40:17 PM8/20/13
to ve...@googlegroups.com
You don't have the Java files compiled, so usually it will look for classes that aren't there. I never used scripts for Java, but it might work, if you'd use container.deployVerticle("EchoServer.java"); and "HelloWorldServer.java" - to tell it to use a file instead of a class.

HTH,
Joern

Angelo K H

unread,
Aug 20, 2013, 6:42:17 PM8/20/13
to ve...@googlegroups.com
It works. Thanks.

Tim Fox

unread,
Aug 21, 2013, 3:24:26 AM8/21/13
to ve...@googlegroups.com
It's a matter of taste, but I prefer to use a script as the main, e.g. starter.js

See http://vertx.io/dev_guide.html#using-a-verticle-to-co-ordinate-loading-of-an-application

John Troxel

unread,
Mar 4, 2015, 11:23:00 PM3/4/15
to ve...@googlegroups.com
I have a module that specifies a js script as the main verticle, which then uses deployVerticle to load a collaborating verticle (script).  This works when I just run the verticle, but does not when I run with the maven runMod target.  With runMod it seems like the deployVerticle does not load the 2nd verticle.  Any ideas?

 - John

Jez P

unread,
Mar 5, 2015, 2:46:04 AM3/5/15
to ve...@googlegroups.com
Could you share a stripped down version of your project on github? I do the same with no problems whatsoever.

John Troxel

unread,
Mar 5, 2015, 1:43:29 PM3/5/15
to ve...@googlegroups.com
See https://github.com/jtroxel/mystack

vertx run src/main/resources/server.js
 - works
mvn vertx:runMod
 - hangs after sending payload on the bus

Test with curl localhost:8080/ratings

Thanks in advance, John

Jez P

unread,
Mar 5, 2015, 2:10:11 PM3/5/15
to ve...@googlegroups.com
Hmmmm, I'm going to have to faff around with jruby on my machine I think. All looks fine. Just one thing, not that I think this should make a difference, but shouldn't ratings.rb be deployed as a worker verticle. You're doing db writes, which are almost certainly blocking calls.

That doesn't really explain why it would be different between a maven run and a run using vertx run though.

Jez P

unread,
Mar 5, 2015, 2:39:01 PM3/5/15
to ve...@googlegroups.com
Hmm, if i just do mvn clean compile vertx:runMod I get connection refused on 8080, so I'm not even seeing server.js starting correctly.


On Thursday, March 5, 2015 at 6:43:29 PM UTC, John Troxel wrote:

Jez P

unread,
Mar 5, 2015, 2:44:33 PM3/5/15
to ve...@googlegroups.com
The location of your main script in mod.json looks wrong to me. That won't be where the script will be found following compilation.

Furthermore, if you wan to use runMod, you need to compile first to put all the resources in the right place relative to the classpath,
so you'd need to mvn compile vertx:runMod (if I do this currently I don't see the http server starting up properly).

On Thursday, March 5, 2015 at 6:43:29 PM UTC, John Troxel wrote:

Jez P

unread,
Mar 5, 2015, 2:54:48 PM3/5/15
to ve...@googlegroups.com
By the way the reason it's failing, I'm pretty sure, is because your rb file is not being found on the classpath, but the reason for that isn't clear. I think the problem is that that verticle is (silently) not being deployed when you run via runMod (which I would normally expect to be because it's not ending up on the classpath). This means the message is going onto the event bus but not being picked up and processed

Jez P

unread,
Mar 5, 2015, 2:55:45 PM3/5/15
to ve...@googlegroups.com
(You shouldn't need src/main/resources littered through your code to make this stuff work)

Jez P

unread,
Mar 5, 2015, 3:09:31 PM3/5/15
to ve...@googlegroups.com
Added a little debug output to check what happened when you try to deploy the ruby verticle:

[INFO] CTRL-C to stop server
Mar 05, 2015 8:05:55 PM org.vertx.java.platform.impl.resolver.HttpResolution
INFO: Downloading io.vertx~lang-jruby~2.1.0-final. Please wait...
Mar 05, 2015 8:06:01 PM org.vertx.java.platform.impl.DefaultPlatformManager
INFO: Module io.vertx~lang-jruby~2.1.0-final successfully installed
Deployment failed! org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- active_record

I suspect the ruby module system isn't playing nicely with the vert.x one when using maven. However, I don't know a lot about using vert.x with ruby, but the failure is because that file is failing to deploy, because it references active_record (presumably from a gem, which isn't being picked up by the maven setup). 

Sorry I can't help more, but I'm Java/Groovy and have zero handle on how Ruby gems are supposed to get picked up when using runMod.

John Troxel

unread,
Mar 5, 2015, 6:34:00 PM3/5/15
to ve...@googlegroups.com
Well that makes sense:  when running plain vertx run it uses the gem path from the current environment, but maven is probably going to want to set up that path explicitly.  Guess I need to re-read the modules and ruby docs to see how that is done.

Can I ask how you got the additional console logging?

Thanks for your help.

 - John

John Troxel

unread,
Mar 5, 2015, 9:17:18 PM3/5/15
to ve...@googlegroups.com
OK removing the relative path of the resources (src/main/resources) worked.  I committed the fix, and made the ruby script a worker as well.  https://github.com/jtroxel/mystack

BTW, I did not have to mess with anything classpathy.  I believe that, since vertx is running jruby, the gem path is still read from the environment.  I added a little more on setting up in the README.

Jez P

unread,
Mar 6, 2015, 2:55:27 AM3/6/15
to ve...@googlegroups.com
Re the extra debug, I added a handler to the deployVerticle call in server.js to provide extra info about whether the verticle deployed successfully (not really proper logging but just to see what was going on):-

console.log("About to deploy child verticle")
container.deployVerticle('ratings.rb', function(err, deployID) {
  if (!err) {
    console.log("The verticle has been deployed, deployment ID is " + deployID);
  } else {
    console.log("Deployment failed! " + err.getMessage());
  }
});

This is documented for vert.x 2 at http://vertx.io/core_manual_js.html#getting-notified-when-deployment-is-complete - verticle deployment is asynchronous.

Of course my issue locally was that I didn't have the gem installed, but maybe just removing the relative path was enough for you, so in fact the gems were being picked up fine in Maven, and it was just the relative path issue in your case, so in effect I was looking at a different problem. Glad you're up and running :)

The worker issue would probably not be a problem during dev (where you're not hitting things hard) but would kill your server as soon as you had more than a few simultaneous requests so running anything using JDBC as a worker is pretty much mandatory.
Reply all
Reply to author
Forward
0 new messages