How to pass deployment options to io.vertx.core.Starter?

1,496 views
Skip to first unread message

Gwowen Fu

unread,
Feb 22, 2016, 11:55:58 AM2/22/16
to vert.x
Hi,

I am a novice and I am running the fat jar with the <Main-Class>io.vertx.core.Starter</Main-Class> in pom file.

I configure my deployment options in the verticle's main method and the main method is not executed if I run the fat jar.

How could I pass deployment options to the io.vertx.core.Starter class or how could I run the main method when fat jar is used?

Thank you!

Mumuney Abdlquadri

unread,
Feb 22, 2016, 12:00:38 PM2/22/16
to ve...@googlegroups.com
are you using this https://github.com/vert-x3/vertx-examples/tree/master/maven-simplest

If you show your code. You will get more help.

--
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 https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/0ca7c8e8-27dc-4f09-bb46-3d9b254976de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Gwowen Fu

unread,
Feb 22, 2016, 12:40:28 PM2/22/16
to vert.x
Here is my verticle with main method:

package io.vertx.simple;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.ServerWebSocket;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.core.logging.SLF4JLogDelegateFactory;
import io.vertx.core.net.JksOptions;

public class VideoChatVerticle extends AbstractVerticle {

Logger logger = LoggerFactory.getLogger(VideoChatVerticle.class);

@Override
public void start(Future<Void> fut) throws Exception {
logger.debug("Verticle started " + Thread.currentThread().getName());
HttpServerOptions options = new HttpServerOptions().setSsl(true).setWebsocketSubProtocols("wss").setKeyStoreOptions(
new JksOptions().setPath("keystore.jks").setPassword("password"));
vertx.createHttpServer(options)
.websocketHandler(webSocket -> {
logger.debug("New client connected: " + ((ServerWebSocket) webSocket).remoteAddress());
logger.debug("path= " + webSocket.path());
logger.debug("uri= " + webSocket.uri());
logger.debug("localAddress= " + webSocket.localAddress());
logger.debug("textHandlerID= " + webSocket.textHandlerID());
webSocket.handler(new Handler<Buffer>() {
public void handle(Buffer data) {
logger.debug(data.toString());
}
});
webSocket.closeHandler(new Handler<Void>() {
@Override
public void handle(Void arg0) {
logger.debug("Close handler. arg0=" + arg0);
}
});
   });
}


public static void main(String[] args) {

Properties properties = new Properties();

try {
            properties.load(new FileInputStream("app.properties"));
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
     
int numInstance = Integer.valueOf(properties.getProperty("numInstance"));
System.setProperty(LoggerFactory.LOGGER_DELEGATE_FACTORY_CLASS_NAME, SLF4JLogDelegateFactory.class.getName());
VertxOptions options = new VertxOptions();
options.setBlockedThreadCheckInterval(1000*60*60);
DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(numInstance)
.setHa(false);
   Vertx.vertx(options).deployVerticle(VideoChatVerticle.class.getName(), deploymentOptions);
}

}
My pom file:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>


  <groupId>io.vertx.simple</groupId>

  <artifactId>simple</artifactId>

  <packaging>jar</packaging>

  <version>0.1</version>

  <name>Project - simple</name>

  <url>http://maven.apache.org</url>


  <dependencies>

    <dependency>

      <groupId>io.vertx</groupId>

      <artifactId>vertx-core</artifactId>

      <version>3.2.1</version>

    </dependency>

    <dependency>

  <groupId>io.vertx</groupId>

  <artifactId>vertx-web</artifactId>

  <version>3.2.1</version>

</dependency>

    <dependency>

      <groupId>io.vertx</groupId>

      <artifactId>vertx-unit</artifactId>

      <version>3.2.1</version>

      <scope>test</scope>

    </dependency>

<dependency>

  <groupId>io.vertx</groupId>

  <artifactId>vertx-hazelcast</artifactId>

  <version>3.2.1</version>

</dependency>    

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>4.12</version>

      <scope>test</scope>

    </dependency>

    <dependency>

<groupId>ch.qos.logback</groupId>

<artifactId>logback-classic</artifactId>

<version>1.1.5</version>

</dependency>

  </dependencies>


  <build>

    <plugins>

      <plugin>

        <artifactId>maven-compiler-plugin</artifactId>

        <version>3.3</version>

        <configuration>

          <source>1.8</source>

          <target>1.8</target>

        </configuration>

      </plugin>

      <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-shade-plugin</artifactId>

        <version>2.3</version>

        <executions>

          <execution>

            <phase>package</phase>

            <goals>

              <goal>shade</goal>

            </goals>

            <configuration>

              <transformers>

                <transformer

                  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

                  <manifestEntries>

                    <Main-Class>io.vertx.core.Starter</Main-Class>

                    <Main-Verticle>io.vertx.simple.VideoChatVerticle</Main-Verticle>

                  </manifestEntries>

                </transformer>

              </transformers>

              <artifactSet/>

              <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>

            </configuration>

          </execution>

        </executions>

      </plugin>

    </plugins>

    <resources>

      <resource>

        <directory>src/main/resources</directory>

      </resource>

    </resources>    

  </build>


</project>

Gwowen Fu

unread,
Feb 22, 2016, 12:58:09 PM2/22/16
to vert.x
I figured out how to run the fat jar with the main method. Just replace the <Main-Class>io.vertx.core.Starter</Main-Class> with the verticle class name that has the main method.

Now the question left is how to pass deployment options to the Starter class. I think I need to subclass io.vertx.core.Starter but don't know exactly what to do.

On Monday, February 22, 2016 at 10:55:58 AM UTC-6, Gwowen Fu wrote:

Mumuney Abdlquadri

unread,
Feb 22, 2016, 1:46:25 PM2/22/16
to ve...@googlegroups.com
This is how I do it.

I don't use main methods in Verticles. Vertx will call your Verticles' start method. so put all your initialisation code there. Since you have only one verticle and it has been declared main in your pom. you don't need to explicitly deploy it.

However you can have a deployerVerticle that only deploys Verticles and that will be your main Verticle.


So in your case, you can create another verticle called 'Deployer'. Put that in your pom as main Verticle. Deploy your VideoChatVerticle in it passing in the deployment options.

I hope you understand this.

--
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 https://groups.google.com/group/vertx.

Gwowen Fu

unread,
Feb 22, 2016, 4:02:22 PM2/22/16
to vert.x
Hi Mumuney, 

Thanks for your suggestions. I like the Deployer approach to set DeploymentOptions for other verticles. 
The problem with this approach is I don't know how to set VertxOptions since the Deployer extends AbstractVerticle and Vertx.vertx(options) is not allowed.
Is there a way set VertxOptions in the Deployer class?

Thank you!

Clement Escoffier

unread,
Feb 23, 2016, 2:23:09 AM2/23/16
to ve...@googlegroups.com
Hi,

First you should use Launcher instead of Starter (as Starter is deprecated and may be removed at some point).

There is a “mapping” between system properties and Vert.x Options as in:
-Dvertx.options.workerPoolSize=20 

The deployment options of the main verticle can also be configured from system properties:
-Dvertx.deployment.options.worker=true

The Launcher class supports a couple of options such as:
- worker
- cluster
- ha
- instances
- conf

You can get the complete list by launching your fat jar with -h:
java -jar your-fat-jar.jar -h -> Get the list of Launcher command
java -jar your-fat-jar.jar run -h -> Get the Run command options (run is the default command)

Clement


Gwowen Fu

unread,
Feb 23, 2016, 11:52:25 AM2/23/16
to vert.x
Thanks Clement,

Your post solved my the other problem that launching app with java -jar didn't show up in the vertx list command. I moved the -D options after -jar target/... then it showed up in the list.

It is good to know there is a “mapping” between system properties and Vert.x Options. Where could I get the complete list. What I really need is
to setBlockedThreadCheckInterval in my Deployer verticle for debugging purpose.

        VertxOptions options = new VertxOptions();

        options.setBlockedThreadCheckInterval(1000*60*60);


Thank you!

Gwowen

...
Reply all
Reply to author
Forward
0 new messages