Eventbus Future Proxy - rapatao/vertx-java-helper GitHub Wiki
The ProxyServiceCreator create an instance of given Service that will call the Vertx EventBus using the "send" method and will return a Future with the handler result.
interface Service {
Future<String> someMethod(String argument);
}
final Service service = ProxyCreator.toEventBus(vertx.eventBus()).asSend(Service.class);
final Future<String> stringFuture = service.someMethod("test");
stringFuture.setHandler(handler -> {
context.assertEquals("future complete: test 1", handler.result());
async.complete();
});
The ServiceRegister class get all methods of an interface provided by the given instance and will create a Vertx EventBus Consumer for each method.
public class ServiceImpl implements Service {
@Override
public Future<String> someMethod(String argument) {
final Future<String> future = Future.future();
future.complete("future complete: test 1");
return future;
}
}
ServiceRegistry.toEventBus(vertx.eventBus()).withPrefix("").to(new ServiceImpl()).registry();
- The service implementation must have only one interface
- You cannot override any service methods.
- All methods arguments must be decoded with io.vertx.core.json.Json#decode
- When using:
- "asSend": The service method does need to return a "Future".
- "AsPublish": The service method does not need to have a return statement.