Vertx command line

 

 ---- IntelliJ create a run configuration (the Application), a io.vertx.core.Launcher class as the main class, the program input parameters: run your-verticle-fully-qualified-name - redeploy = ** / *. class --launcher-class = io.vertx.core.Launcher. In order to trigger the re-deployment, or the need to display items generation module (Build menu-> Make project).

 run your-verticle-fully-qualified-name--redeploy=**/*.class --launcher-class=io.vertx.core.Launcher

Vertx command line

vertx command line commands are used to interact with Vert.x. This is the main way of running Vert.x the verticle. To run the command line, you need to download and install Vert.x release, and add the path to the installation bin path to the PATH environment variable. At the same time it must be confirmed Java8 the JDK installed, and the executable from the command line.

Note: You need to support JDK java compiled code runs.

 Run Verticles

You can use vertx run directly from the command line Vert.x veticles run a native. There are one or two examples of run commands.

vertx run my-verticle.js                                 (1)

vertx run my-verticle.groovy                             (2)

vertx run my-verticle.rb                                 (3)

 vertx run io.vertx.example.MyVerticle                    (4)

vertx run io.vertx.example.MVerticle -cpmy-verticle.jar (5)

 vertx run MyVerticle.java

 1. Deployment of a JavaScript verticle

2. Deployment of a Groovy verticle

3. Deploying a Ruby veticle

4. Deployment of an already compiled java verticle, the root class path is the current directory.

5. Deploying a package labeled verticle jar, jar package must be in the class path.

6. Compile the Java source code and deployment. ,

As you can see, in the Java example, the name could be the name of security Verticle class integration rules, you can also directly refer to the Java source code files, Vert.x will compile it for you.

Can also be added to achieve the language prefix in front of verticle name. For example, if Verticle is a compiled Groovy class, you can add groovy: prefix, in order to know in Vert.x, which is a Groovy class rather than a Java class.

Vertx rungroovy: io.vertx.example.MyGroovyVerticle

vertx run command can have some optional parameters, they are:

· -Conf <config_file> provide some configuration to verticle. config_file is the name of a text file that contains JSON object. When the JSON object represents the configuration verticle object, which is optional.

· -Cp <path> - This is the path of some other resources to find a path verticle and is verticle to use. Default. "" (Current path). If verticle refer to other scripts, classes, or other resources (such as a jar file), make sure they are in this path. This path may comprise a plurality of physical paths, there is: or; separated, what specific operating system dependent separator. Each path can be an absolute path entity can also be a path for the file that contains the script, or absolute, relative and file name of the jar / zip file. Examples of such a path might be -cpclasses: lib / otherscripts: jars / myjar.jar: jars / otherjar.jar. Always use the path references some resources verticle needed. Do not use these resources in the system classpath, as this can cause problems in isolation between the deployment of verticle.

· -Instance <instance> - the number of initial veticle instance. Verticle each instance is a strict single-threaded, so as to expand on core operations to get all applications should deploy multiple instances. If we ignore this parameter, verticle single instance will be deployed.

· -Worker- This option determines whether a work is verticle verticle.

· -Cluster-port cluster if the option is set, this parameter depends on which port to perform communications with other Vert.x instance. The default is 0, indicating that a randomly selected empty port. Usually not required unless you really need to bind to the specified port this parameter.

· -Cluster-host if the cluster option is specified, this parameter determines the host address is used for communications with other Vert.x instance. The default is to select one of the available addresses. If you have multiple network cards, you need to use the specified settings here.

· -Ha If verticle be deployed into highly available. Refer to the relevant section for more information.

· -Quorum and -ha parameter combination. This parameter specifies the minimum number of nodes in the cluster, the HA nodes in order to activate deployment ID. The default is 0.

· -Hagroup and -ha parameter combination. Designated HA node to join the group. There may be multiple HA groups on a cluster. When a node fails, other nodes in the same group by the backup. The default is `__DEFAULT__`

-Dkey = value may also be used to set the system properties

Here are some more examples, using default settings running the javascript verticleserver.js.

vertx run server.js

Run precompiled java verticle 100 instances, and specify a class path:

vertx run com.acme.MyVerticle -cp"classes:lib/myjar.jar" -instances 10

Example 10 run from the source file java verticle

vertx run MyVerticle.java -instances 10

Work verticle20 instances running ruby

vertx run order_worker.rb -instances 20 –worker

Javascript running two instances on the same machine, and let it clusters together

vertx run handler.js -cluster

vertx run sender.js –cluster

Some of the parameters passed to run a Ruby verticle

vertx run my_verticle.rb -conf my_verticle.conf

my_verticle.conf may contain as following:

{

 "name": "foo",

 "num_widgets": 46

}

Through the kernel API, within the verticle, the configuration can be acquired. When using vert.x high availability features, you may want to create a bare vert.x instance. After starting this instance, does not deploy any verticles. However, if the cluster node crashes, it will receive a verticle. To create bare instance, start as follows:
VertX -ha

Depending on the cluster configuration, it may be necessary to add the cluster-host and cluster-port parameters.

 Vert.x application execution from a fat jar in

A fat jar package is a built-dependent executable jar package. This means that you do not have to pre-install Vert.x on the machine, and then execute jar. Some executable java jar similar package, so that it can be executed:

java -jar my-application-fat.jar

About this, Vert.x there is no need to set some applications can do so. You can also create and set up in the main program mainfest but recommended verticle write your own code and use Vert.x the Launcher (io.vertx.core.Launcher) class as your main class. The main operation and the command line is the same Vert.x main classes, thus allowing to specify command line parameters, such as application instances allow easier stretching.

In order to deploy verticle with fat jar way, there must be a manifest:

· Main-Class is set to io.vertx.core.Launcher

· Main-Verticle specify the primary verticle (the full strict class name or the name of the script file

Generic commands may be passed to the command line parameters vertx run.

java -jar my-verticle-fat.jar -cluster -confmyconf.json

java -jar my-verticle-fat.jar -cluster -confmyconf.json -cp path/to/dir/conf/cluster_xml

 By default, a run command fat jar.

 Display Vert.x version

Display Vert.x version with the following command:

vertx version

 Other commands

Launcher vertx command and other commands are provided in addition to the run command and a version may be created with the following code for instance a bare:

Vertx only

# or

java -jar my-verticle-fat.jar bare

You can start an application in the background:

java -jar my-verticle-fat.jar start-Dvertx-id=my-app-name

If the my-app-name is not set, a random generating an ID, and outputs to the command prompt. run options can be passed to the start command:

java -jar my-verticle-fat.jar start-Dvertx-id=my-app-name –cluster

Once the background is loaded, can stop command to stop:

java -jar my-verticle-fat.jar stop my-app-name

You can also list Vert.x applications running in the background:

java -jar my-verticle-fat.jar list

start, stop and list commands can also be found from vertx tool. start command supports several options: value

· Vertx-id: application ID, is not set, a random UUID

· Java-opts: JVM option, if not set, use the JAVA_OPTS variable

· Redirect-output: redirect the output and error to start the process stream flow to the parent process.

If the option value contains spaces, you must use double quotation marks

Since the start command start a new process, incoming JVM option does not spread. All must be 'java-opts' configuration JVM. If you set the CLASSPATH environment variable, be sure to include all of the required jar package (vert-xore, application jar and all the dependencies)

Command set is extensible, the reference spreading vert.x loader section.

 Hot deployment

Automatically re-deploy the application when the file changes in the development of applications is very convenient. vertx command-line tools and more common Launcher class provides this feature. Here are some examples:

vertx run MyVerticle.groovy--redeploy="**/*.groovy" --launcher-class=io.vertx.core.Launcher

vertx run MyVerticle.groovy--redeploy="**/*.groovy,**/*.rb" --launcher-class=io.vertx.core.Launcher

java io.vertx.core.Launcher runorg.acme.MyVerticle --redeploy="**/*.class"  --launcher-class=io.vertx.core

.Launcher -cp ...

Re-deployed to achieve the following. First, the application after application loading station (with a start command). Matching file changes, the application process is stopped and restarted. This prevents leakage.

In order to enable enforcement deployment, adding -redeploy option to run the command. --redeploy specify the file to be monitored collection. This collection of files using Ant-style mode (with **, * and?) Match. You can refer to pass by "," separated by a specified multiple collections. Mode is relative to the current working directory.

The parameter passed to run the command is passed to the application. Available -java-opts to set JVM options.

--launcher-class option specifies the application to start the main class. Usually Launcher, but also you can use your own master class.

Weight characteristics may be used in the IDE deployed:

· Eclipse --- create a run configuration (Run configuration), with io.vertx.core.Launcher class as the main class. In the region of the program parameters (parameter tag), an input run your-verticle-fully-qualified-name -. Redeploy = ** / * java --launcher-class = io.vertx.core.Launcher. You can also add other parameters. When you save a file, Eclipse will be incremental compilation modified files, re-deployment smooth work.

· IntelliJ ---- create a run configuration (the Application), a io.vertx.core.Launcher class as the main class, the program input parameters: run your-verticle-fully-qualified-name - redeploy = ** / * .class --launcher-class = io.vertx.core.Launcher. In order to trigger the re-deployment, or the need to display items generation module (Build menu-> Make project).

In order to debug your application, create your run configuration and configure the application as a remote debugger with -java-opts. However, do not forget to reinsert the debugger each time you re-deploy a new process.

It can also hook under the build process in the deployment cycle.

java -jar target/my-fat-jar.jar--redeploy="**/*.java" --on-redeploy="mvn package"

java -jar build/libs/my-fat-jar.jar--redeploy="src/**/*.java" --on-redeploy='./gradlew shadowJar'

on-redeploy option to specify a command in the application after application restart or shut down the call, so you can hook letter build tool, if the update some operating resources. Such as starting gulp or grunt update your resources.

Re-deployment features support the following settings:

· Redeploy-scan-period: the file system check cycle, in milliseconds, default 250ms

· Redeploy-grace-period: The default is 1000ms waiting time between two different worlds deployment in milliseconds

redeploy-termination-period: the amount of waiting time before the start of the user command after stopping use. This is useful on Windows, because the process is not legislation is both kill. Milliseconds, the default value is 0ms.

Guess you like

Origin www.cnblogs.com/endv/p/11265159.html