Vertx And Spring Integration for multiple deployment of the verticles

28 views
Skip to first unread message

Vasu Sethia

unread,
Jul 1, 2022, 2:18:13 AMJul 1
to vert.x
Hi All, 
I have been trying to integrate vertx and spring. I was able to deploy on verticle successfully but I am failing to deploy more than 1 verticle. Following is my main.java

package com.example.LogoutRequest;


import com.example.LogoutRequest.logoutservice.LogoutRequestService;
import com.example.LogoutRequest.verticles.LoginRequestVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;

import javax.annotation.PostConstruct;

@SpringBootApplication
@EnableAsync
public class Main {

private static Logger logger = LogManager.getLogger(Main.class);
@Autowired
private LogoutRequestService logoutRequestService;

@Autowired
private LoginRequestVerticle loginRequestVerticle;

public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}

@PostConstruct
public void deployVerticles() {

// DeploymentOptions options = new DeploymentOptions().setInstances(4);
Vertx vertx = Vertx.vertx();

vertx.deployVerticle(loginRequestVerticle, res -> {
if(res.succeeded()){
logger.info("Verticles deployed successfully");
}else{
logger.error("Deployment failed");
}
});
}
}
as soon as I uncomment deployement options I get the following error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'main': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Can't specify > 1 instances for already created verticle. 
How to fix this?

Himanshu Gupta

unread,
Jul 2, 2022, 1:47:35 AMJul 2
to vert.x
Did you annotate the LoginRequestVerticle as singleton?

You need it to be of type prototype to create more than 1 instance. 

And rather than giving the loginRequestVerticle in the deployVerticle, give the class name (LoginRequestVerticle.class)

Vasu Sethia

unread,
Jul 2, 2022, 4:47:16 AMJul 2
to vert.x
I didn't annotate m LoginRequestVerticle as singleton
I tried annotating my verticle with the type prototype and like you suggested I gave LoginRequestVerticle.class but the issue I am facing is that all the things which are autowired in my LoginRequestVerticle is coming as null, any ideas behind it?

Himanshu Gupta

unread,
Jul 3, 2022, 2:20:54 AMJul 3
to vert.x
I think I get where you are getting.

Try using.

@Autowired private ApplicationContext context;

and in the deployVerticle use: 

context.getBean(LoginRequestVerticle.class)

Himanshu Gupta

unread,
Jul 3, 2022, 2:24:18 AMJul 3
to vert.x

Vasu Sethia

unread,
Jul 4, 2022, 1:27:46 AMJul 4
to vert.x
Tried this, but seems like I am getting the same error
Can't specify > 1 instances for already created verticle
Let me see the links you have sent.
Reply all
Reply to author
Forward
0 new messages