Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how do i deploy additional verticles? #64

Open
jeff3parker opened this issue Sep 25, 2017 · 1 comment
Open

how do i deploy additional verticles? #64

jeff3parker opened this issue Sep 25, 2017 · 1 comment
Labels

Comments

@jeff3parker
Copy link

I'm relatively new to Vertx and I'm strugging how do I bootstrap adding and initializing additional verticles in conjunction with the JerseyVerticle? For example I'd like to push data onto the EventBus from a request and have another verticle handle and respond to it.

How is this done with vertx-jersey + vertx-hk2?

e.g. // The Jersey Resource

   @POST
    @Path("/")
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    @Produces(MediaType.TEXT_PLAIN)
    public Response exampleRequest(MonitorRequest request, @Context Vertx vertx) {
    	try {
			vertx.eventBus().send("gather.data", mapper.writeValueAsString(request));
		} catch (JsonProcessingException e) {
			logger.error(e);
		}
    	return Response.status(200).entity("working on request...").build();
    }

// The other Verticle

public class SomeBizService extends AbstractVerticle implements Handler<Message<Void>> {
...
    void init()
    {
     vertx.eventBus().consumer("gather.job.data", this::handle);
  }

	@Override
	public void handle(Message<Void> event) {
		System.out.println("received message to handle "+event.body());
	}
}
@adrianluisgonzalez
Copy link
Member

It depends how you start your vertx application.

If you start via a Main class, then you can just deploy the JerseyVerticle in addition to your SomeBizService verticle after you have created the vertx instance.

If you run a fat jar (ie. maven-shade-plugin) or via the vertx command line, then you probably want to have a bootstrap verticle that is responsible for deploying the JerseyVerticle and SomeBizService.

As long as vertx-hk2 and vertx-jersey are on the class path, then you can programmatically deploy the JerseyVerticle as described in the README.md:

vertx.deployVerticle(SomeBizService.class.getName(), config);
vertx.deployVerticle("java-hk2:com.englishtown.vertx.jersey.JerseyVerticle", jerseyConfig);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants