Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

automatic registration in the vertx ServiceDiscovery #9

Open
fiorenzino opened this issue Mar 22, 2018 · 6 comments
Open

automatic registration in the vertx ServiceDiscovery #9

fiorenzino opened this issue Mar 22, 2018 · 6 comments

Comments

@fiorenzino
Copy link
Contributor

Another suggestion:

the automatic registration of rest service on ServiceDiscovery should be interesting.

for example:
@ServiceDiscovery("api.name", "host", port, "root")
@path("/")
public FlowerService {

}

translated in vertx:
Record record = HttpEndpoint.createRecord(name, host, port, root, new JsonObject().put("api.name", name));
serviceDiscovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions().setBackendConfiguration(config()));
serviceDiscovery.publish(record, ar ->
{
if (ar.succeeded())
{
registeredRecords.add(record);
logger.info("Service <" + ar.result().getName() + "> published");
future.complete();
}
else
{
future.fail(ar.cause());
}
});

what do you think about it?

@FroMage
Copy link
Owner

FroMage commented Mar 22, 2018

That's very interesting, except I think the host/port parts should come from the current config, no? It seems error-prone to specify them in the code when they are deployment-dependent. I guess the same could be said of the root.

But certainly, it would be useful to declare services with an annotation. I think the name should be enough, the rest we can get from the config.

@fiorenzino
Copy link
Contributor Author

Yes, the host/port/root parts are always derived from server config and @path annotations.
But in vertx you must declare that.

@FroMage
Copy link
Owner

FroMage commented Mar 22, 2018

Sure, but they don't belong in the annotation if the framework can detect them. Unless they're not required/defaulted.

@fiorenzino
Copy link
Contributor Author

If you like my idea, i can try to write my first extension on redpipe: redpipe-servicediscovery, dependent from redpipe-cdi.

We need to initialize in some point:
ServiceDiscovery serviceDiscovery = ServiceDiscovery.create(AppGlobals.get().getVertx(), new ServiceDiscoveryOptions().setBackendConfiguration(AppGlobals.get().getConfig()));
AppGlobals.get().setGlobal("serviceDiscovery", serviceDiscovery);

Two annotations:
@service(name="name", host="localhost", port=8081, path="/") for JAXRS resources.
Where name, host, port, path are optionals:

  • host=> config().get("http_address")
  • port => config().get("http_port")
  • path=> default value is "/"
  • name=> default value is java className

@ServiceClient(name="name")
where name is the service name.

The example use for service:
@path("/")
@ApplicationScoped
@service
public class UsersService {}

and for the client:
@ServiceClient(name="name")
Single serviceClient;
and in some method:

serviceClient.subscribe((client) -> {
if (client == null) {
System.out.println("no client");
} else {
Single<HttpResponse> req= client.get("/path").rxSend();
req.map(response -> {
resultHandler.toHandler().handle(Future.succeededFuture(response.body().toString()));
return "";
}).subscribe();
}
});

what do you think about it?

@FroMage
Copy link
Owner

FroMage commented Apr 4, 2018

Yes this sounds great.

@fiorenzino
Copy link
Contributor Author

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

No branches or pull requests

2 participants