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

Use the Original ServiceImpl inside the RestVerticle can result in a vertx context issue #21

Open
a-marcel opened this issue Feb 17, 2017 · 0 comments

Comments

@a-marcel
Copy link

a-marcel commented Feb 17, 2017

Hi,

inside your verticles you deploy the rest api with the same instance, created in the verticle.

// create the service instance
ProductService productService = new ProductServiceImpl(vertx, config());
// register the service proxy on event bus
ProxyHelper.registerService(ProductService.class, vertx, productService, SERVICE_ADDRESS);
...
.compose(servicePublished -> deployRestService(productService))
...

As an example:

  • you could use a http client inside your ProductServiceImpl (and create this one time with the constructor)

  • inside ProductServiceImpl there is a method "test" wich one use this http client

  • and following changes in the ProductVerticle:

private Future<Void> bindEventBusListener(ProductService productService) {
  Future<Void> future = Future.future();
  vertx.eventBus().consumer("cqrs.channel", m -> {
    productService.test(); // <--- this is important
  }).completionHandler(future.completer());
  return future.map(r -> null);
}

you will run in this:

[vert.x-eventloop-thread-1] WARN io.vertx.core.http.impl.ConnectionManager - Reusing a connection with a different context: an HttpClient is probably shared between different Verticles

as a solution, you should give a proxy instance inside the Rest API and inside the eventbus consumer.

ProductServiceVertxEBProxy productServiceProxy = new ProductServiceVertxEBProxy(vertx, SERVICE_ADDRESS);

...
.compose(servicePublished -> deployRestService(productServiceProxy))
.compose(servicePublished -> bindEventBusListener(productServiceProxy))
...

Maybe you ask why a eventBus consumer inside you verticles is needed. In my project i use CQRS and communicate with events.

As an example:

i've a customer and a email messaging verticle in your style.

a customer calls register and we write the data into a database and return the customer maybe a access_token.
at the same time, we're using the eventbus to send a CUSTOMER_REGISTER event.

this CUSTOMER_REGISTER is subscribed inside the messaging verticle and will send a email with a confirmation code to this customer
after that, the messaging verticle send a CONFIRMATION_MAIL_SEND event (including the generated confirmation code)

this CONFIRMATION_MAIL_SEND is subscribed by the customer verticle and save this confirmation code inside the customer database (via this testMethod from above)

i hope, i could describe my topic

Thanks
Marcel

P.s: i forget one thing to mention. both verticles DON'T share any Java Classes or generated code (to keep them decoupled). They just send plain JsonObject's to a channel.

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

No branches or pull requests

2 participants