Vert-x3 deploying a verticle

1,114 views
Skip to first unread message

vik

unread,
Jan 27, 2015, 10:41:33 AM1/27/15
to ve...@googlegroups.com
Hello all,

Running vertx in eclipse using a class with main() method.

Trying to figure out how vertx services can be called from within main(). Tried to call a vertx-mail as a service as follows after downloading & importing vertx-mail from github.


JsonObject config = new JsonObject().put("name", "tim").put("directory", "/blah");
config
.put("address", "mye...@gmail.com");

DeploymentOptions options = new DeploymentOptions().setConfig(config);

vertx
.deployVerticle("service:io.vertx:vertx-mail", options );




But I'm getting the following exception.

Jan 27, 2015 7:05:23 AM io.vertx.core.impl.DeploymentManager
SEVERE: io.vertx:vertx-mail
java.lang.ClassNotFoundException: io.vertx:vertx-mail
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)

Appreciate your help if someone can guide me on what I'm doing wrong. Thanks for your help in advance.

Johannes Schüth

unread,
Jan 27, 2015, 11:09:00 AM1/27/15
to ve...@googlegroups.com
Hi,

i assume you want to deploy your verticle using maven (vertx-maven-service-factory). In that case you have to add the following maven depenency.
<dependency>
 
<groupId>io.vertx</groupId>
       
<artifactId>vertx-maven-service-factory</artifactId>
       
<version>${vertx.version}</version>
</dependency>

You also need to add the version to your deployment identifier. (service:io.vertx:vertx-mail:X.Y.Z)

Tim Fox

unread,
Jan 27, 2015, 11:14:30 AM1/27/15
to ve...@googlegroups.com
Perhaps you could elaborate on what you are trying to achieve? A pointer to your project on GitHub would make things a lot clearer.
--
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.
For more options, visit https://groups.google.com/d/optout.

vik

unread,
Jan 27, 2015, 2:16:56 PM1/27/15
to ve...@googlegroups.com
Thanks Johannes. Hello Tim,

I've created a simple project on git. https://github.com/ThoughtApps/vert-x3-example

I'm just trying to understand a few things:

1) How to call a verticle as a service. For this, I am trying to call vertx-mail service but now get the following error:

yo yo infologger
log4j
:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j
:WARN Please initialize the log4j system properly.
io
.vertx.ext.mail.MailServiceVerticle
java
.lang.ClassNotFoundException: io.vertx.ext.mail.MailServiceVerticle
 at java
.net.URLClassLoader$1.run(URLClassLoader.java:372)
 at java
.net.URLClassLoader$1.run(URLClassLoader.java:361)
 at java
.security.AccessController.doPrivileged(Native Method)



2) Where does the log4j.properties file go?

3) Where to place the conf file?
Ans: Although I'm yet to test it, I noticed in one of the examples that unlike 2.1, we have it in a json file (similar to mod.json) placed in \src\main\resources\com.eform.starter-bootstrap.json

Thanks much ...

Vik

Mumuney Abdlquadri

unread,
Jan 27, 2015, 4:17:46 PM1/27/15
to ve...@googlegroups.com

Alexander Lehmann

unread,
Jan 27, 2015, 6:36:54 PM1/27/15
to ve...@googlegroups.com
To call the service as a verticle via the event bus, you have to create a service proxy with MailService.createEventBusProxy and start the verticle either with vertx run service or deploy the verticle inside your program with deployVerticle.

If you want to use the service only inside a single verticle program, you do not have to use the eventbus, you can call the service directly on one create with MailServer.create, this way you are calling the java code directly.

The log4j.properties file should be in the classpath root, for maven that is src/main/resources or src/test/resources or in the root of the fatjar if you create one (that comes from src/main/resources as well I think).
To enable log4j logging, you need to set the property option for the logging factory though, either in maven, when running the jar or in the vertx options.

Alexander Lehmann

unread,
Jan 29, 2015, 3:58:32 PM1/29/15
to ve...@googlegroups.com
How are you running your program?

I have noticed an issue that is due to one signed jar (bouncycastle) that breaks the fatjar, however that gives another error message.



On Tuesday, January 27, 2015 at 8:16:56 PM UTC+1, vik wrote:

vik

unread,
Jan 30, 2015, 2:00:41 AM1/30/15
to ve...@googlegroups.com
Hello Alexander,

I have managed to run a verticle within the same project. I have a ApplicationStarter class with main ()  where I call vertx.deployVerticle(). So to answer your question, I'm running my program from within eclipse as a Java Application.

Now I'm planning to create a service of my own and that is where I'm stuck.

I have put my sample code on https://github.com/ThoughtApps

So far, I have two projects:

app-starter - starts all the services for my application
email-service - This is the service that I'm creating to send emails. Internally it calls vertx-mail-service

Steps I've followed are:
  1. Updated my starter application pom with dependency: 
    vertx-service-factory
    vertx
    -maven-service-factory
    vertx
    -service-proxy

  2. Updated my service pom with dependency: 
    vertx-service-factor
    vertx
    -maven-service-factory

  3. Created a service descriptor Json file under src/main/resources called com.eform.email-service.1.0.json
  4. Call it from my Application starter class as :
 vertx.deployVerticle("service:com.mycompany:clever-db-service:1.0",new DeploymentOptions(config),  res -> {
     
if (res.succeeded()) {
        log
.info("com.eform.verticles.EmailServiceVerticle: Deployment id is: " + res.result());
     
} else {
        log
.warn("com.eform.verticles.EmailServiceVerticle: Deployment failed!");
     
}
 
});

But it's not working....

vik

unread,
Jan 30, 2015, 2:29:40 AM1/30/15
to ve...@googlegroups.com
I fixed the copy paste error as :
 vertx.deployVerticle("service:com.eform:email-service:1.0-SNAPSHOT",new DeploymentOptions(config),  res -> {

   
if (res.succeeded()) {
      log
.info("com.eform.verticles.EmailServiceVerticle: Deployment id is: " + res.result());
   
} else {
      log
.warn("com.eform.verticles.EmailServiceVerticle: Deployment failed!");
   
}
 
});
   


After some research, I found that the error in my logs is :

Path /com/eform/email-service/1.0-SNAPSHOT/email-service-1.0-SNAPSHOT.jar not found in local storage of repository

Alexander Lehmann

unread,
Jan 30, 2015, 6:24:00 PM1/30/15
to ve...@googlegroups.com
If you are deploying the service via maven, I think you have to install the maven package in your local repo with mvn install at least once.

Eclipse m2e automatically uses the maven projects that are open as dependencies, but that is probably not happening for a maven module in vert.x.

Alexander Lehmann

unread,
Jan 31, 2015, 5:28:19 AM1/31/15
to ve...@googlegroups.com
Actually when using Eclipse, I wonder if it is good to deploy the verticle via maven if that is the project you are currently developing.

You could deploy the verticle inside the current project, otherwise the changes will not be picked up I think.

If you are running a verticle inside the current project, using deployVerticle("class.Name", ... ) is probably easier.

idlemind

unread,
Jan 31, 2015, 6:28:43 AM1/31/15
to ve...@googlegroups.com
Thanks Alexander,

I believe, there should not be any issue deploying a verticle inside a project. Infact, the current project on github already does that. But that would be easy. My current goal is 

  • To develop a component (service) that can be used by multiple projects. 
  • And then the next is to deploy the service on a distributed platform i.e. on a separate server. Only then we would be able to harness the true power of vertx framework.

I'm past the previous problem where the jar was not getting located. Now I'm  at my next hurdle. While deploying a service, the program just stops. No logs and no errors on console. My guess was that the problem is that I didn't have maven-assembly-plugin defined in my service. So, I did that. But I keep getting the following error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4.1:single (package-vertx-service) on project eform-email-service: Error reading assemblies: Descriptor with ID 'eform-email-service' not found -> [Help 1]
org
.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4.1:single (package-vertx-service) on project eform-email-service: Error reading assemblies: Descriptor with ID 'eform-email-service' not found
 

My service descriptor name is :
 com.eform.eform-email-service.1.0-SNAPSHOT.json


My service pom is :I've tried various combinations of "descriptorRef" but none is working.


<?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/xsd/maven-4.0.0.xsd">
 
<modelVersion>4.0.0</modelVersion>


 
<groupId>com.eform</groupId>
 
<version>1.0-SNAPSHOT</version>
 
<artifactId>eform-email-service</artifactId>
 
<name>eform-email-service</name>


 
<parent>
 
<groupId>org.sonatype.oss</groupId>
 
<artifactId>oss-parent</artifactId>
 
<version>7</version>
 
</parent>
 
<properties>
 
<vertx.version>3.0.0-SNAPSHOT</vertx.version>
 
</properties>


 
<dependencies>
 
<dependency>
 
<groupId>io.vertx</groupId>
 
<artifactId>vertx-core</artifactId>
 
<version>3.0.0-dev_preview1</version>
 
</dependency>


 
<dependency>
 
<groupId>io.vertx</groupId>
 
<artifactId>vertx-service-factory</artifactId>

 
<version>${vertx.version}</version>
 
</dependency>


 
<dependency>
 
<groupId>io.vertx</groupId>
 
<artifactId>vertx-maven-service-factory</artifactId>
 
<version>${vertx.version}</version>
 
</dependency>



 
<dependency>
 
<groupId>io.vertx</groupId>
 
<artifactId>vertx-service-proxy</artifactId>

 
<version>${vertx.version}</version>
 
</dependency>



 
<dependency>
 
<groupId>io.vertx</groupId>
 
<artifactId>vertx-mail</artifactId>
 
<version>1.0-SNAPSHOT</version>
 
</dependency>


 
<dependency>
 
<groupId>org.apache.logging.log4j</groupId>
 
<artifactId>log4j-api</artifactId>
 
<version>2.1</version>
 
</dependency>




 
<dependency>
 
<groupId>org.apache.logging.log4j</groupId>
 
<artifactId>log4j-slf4j-impl</artifactId>
 
<version>2.0.1</version>
 
</dependency>


 
</dependencies>


 
<build>


 
<pluginManagement>
 
<plugins>
 
<!-- We specify the Maven compiler plugin as we need to set it to Java
 1.8 -->

 
<plugin>
 
<artifactId>maven-compiler-plugin</artifactId>
 
<version>3.1</version>
 
<configuration>
 
<source>1.8</source>
 
<target>1.8</target>
 
</configuration>
 
</plugin>
 
</plugins>
 
</pluginManagement>


 
<plugins>
 
<!-- Define an assembly execution for packaging the vertx service that
 can be reused by children modules -->

 
<plugin>
 
<artifactId>maven-assembly-plugin</artifactId>
 
<version>2.4.1</version>
 
<dependencies>
 
<dependency>
 
<groupId>io.vertx</groupId>
 
<artifactId>vertx-service-factory</artifactId>

 
<version>${vertx.version}</version>
 
</dependency>

 
</dependencies>
 
<executions>
 
<execution>
 
<id>package-vertx-service</id>
 
<goals>
 
<goal>single</goal>
 
</goals>
 
<configuration>
 
<appendAssemblyId>false</appendAssemblyId>
 
<descriptorRefs>
 
<descriptorRef>com.eform.eform-email-service</descriptorRef>
 
</descriptorRefs>
 
</configuration>
 
<phase>package</phase>
 
</execution>
 
</executions>
 
</plugin>




 
<!-- Fat executable jars If you want your project to output a fat executable
 standalone jar with all the dependencies in it you can use the shade 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>com.app.starter.ApplicationStarter</Main-Class>
 
</manifestEntries>
 
</transformer>
 
<transformer
 
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
 
<resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
 
</transformer>
 
</transformers>
 
<artifactSet>
 
<!-- By default all the deps go into the fat jar, but we don't need
 some so we can exclude them here -->

 
<excludes>
 
<exclude>io.vertx:vertx-codegen</exclude>
 
<exclude>junit:junit</exclude>
 
<exclude>org.mvel:mvel2</exclude>
 
<exclude>log4j:log4j</exclude>
 
<exclude>org.slf4j:slf4j-api</exclude>
 
</excludes>
 
</artifactSet>
 
<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
 
</configuration>
 
</execution>
 
</executions>
 
</plugin>


 
</plugins>


 
</build>




</project>

Alexander Lehmann

unread,
Jan 31, 2015, 6:59:22 AM1/31/15
to ve...@googlegroups.com
two things I noticed when looking at your project, the same of the service descriptor does not usually contain the version number (afaik), so the file should be named {groupId}.{projectId}.json, i.e. com.eform.eform-email-service.json

there is a syntax error in the json file where a comma is missing

If you have stored the module in the local .m2 repo, it should be deployable on this machine, to deploy on other machines, creating a fatjar is probably the easiest solution (or you could use a local maven server instance like archiva)
...

idlemind

unread,
Jan 31, 2015, 7:58:49 AM1/31/15
to ve...@googlegroups.com
Thanks again Alaxander,

I've corrected that but still with the same issues during my mvn build lifecycle:  " Descriptor with ID 'vertx-service' not found. " The problem is with  "maven-assembly-plugin"


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4.1:single (package-vertx-service) on project eform-email-service: Error reading assemblies: Descriptor with ID 'vertx-service' not found -> [Help 1]



I think, If this is resolved, my service would get available in mvn local repository and hence visible via vertx-maven-service-factory.

Alexander Lehmann

unread,
Jan 31, 2015, 11:49:46 AM1/31/15
to ve...@googlegroups.com
There is something missing in the pom, I think, but I cannot quite say what. The assembly descriptor vertx-service is available in other projects (e.g. https://github.com/vert-x3/vertx-mysql-postgresql-service, but this pom uses another parent).
If you comment out the assembly plugin entry, the project builds and installs a jar in the local repo, not sure if it will run then.

Tim Fox

unread,
Jan 31, 2015, 12:27:30 PM1/31/15
to ve...@googlegroups.com
On 27/01/15 19:16, vik wrote:
Thanks Johannes. Hello Tim,

I've created a simple project on git. https://github.com/ThoughtApps/vert-x3-example

I'm just trying to understand a few things:

1) How to call a verticle as a service.

Not quite sure what you mean by this.

If you want to use the mail service in your application you don't need to deploy it as a verticle. You can just instantiate it directly.

Tim Fox

unread,
Feb 2, 2015, 4:58:39 AM2/2/15
to ve...@googlegroups.com
On 30/01/15 23:24, Alexander Lehmann wrote:
If you are deploying the service via maven, I think you have to install the maven package in your local repo with mvn install at least once.

This is not the case. If you're deploying using the Maven service factory (btw, this is NOT necessary to use services), then it will retrieve remote dependencies just fine.

Tim Fox

unread,
Feb 2, 2015, 5:00:31 AM2/2/15
to ve...@googlegroups.com
On 27/01/15 19:16, vik wrote:
Thanks Johannes. Hello Tim,

I've created a simple project on git. https://github.com/ThoughtApps/vert-x3-example


This link give me a 404

idlemind

unread,
Feb 2, 2015, 8:59:38 AM2/2/15
to ve...@googlegroups.com
Hello Tim, 

I have the working code in the repository now. Thanks for  your and Alexander's help.

The repository has two projects

It's an example demonstrating three Vert.x3 concepts. Environment is JDK 1.8 with Eclipse Luna. There are a few tricks needed for actually getting it to work and run on eclipse with m2e. I'll document them in the project.

1) Deploy a vertical within the same project
2) Call a Vert-X3 service (in this case vertx email service)
3) Create a service as a separate eclipse project and call from a different eclipse project. In this case, it technically includes the service project jar as a dependency within the same project. 

My next step is to test different models of scaling the application. 

1) Horizontally scale the application over multiple servers. 
2) Deploy the modules (services) of the project on separate servers and interact with them over the eventbus. i.e. Not to including the services as dependencies within the main project.

Alexander Lehmann

unread,
Feb 4, 2015, 6:46:09 AM2/4/15
to ve...@googlegroups.com
Sorry, I didn't quite word that right. The maven service: deployment retrieves the module from the default maven repositories and it has to be stored in one of them at least.

If you are doing company local deployments, you will need a maven repository to make the module available to all your machines or you have to install it into the local .m2 repository on each (in this case a fatjar deployment is probably easier). If the module is in the regular maven repos, it will be found there (e.g. if you deploy service:io.vertx:vertx-mail-server:1.0-SNAPSHOT)
...
Reply all
Reply to author
Forward
0 new messages