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

Fix the access to services from non-java language #54

Merged
merged 12 commits into from Jan 12, 2017
Merged

Conversation

cescoffier
Copy link
Member

This fixes #14. Long time overdue....

So this PR fixes the polyglot issue of the vert.x service discovery. It's not possible to retrieve the "right" type of service for non-Java callers. It provides new methods when using the service reference approach (low level) and service types.

For example, in JavaScript:

discovery.getRecord(function (rec) {
    return rec.name === "my-http-service"
  }, function (rec, err) {
    var result = {};
    if (! err) {
      var reference = discovery.getReference(rec);
      // reference.getService(Class) is a new method returning the right object
      // HttpClient is the JS HttpClient (got from var HttpClient = require("vertx-js/http_client");)
      var client = reference.getService(HttpClient);
    }
  });

When using service types it does:

HttpEndpoint.getClient(discovery, function (rec) {
    return rec.name === "my-http-service"
  }, function (res, err) {
    if (! err) {
       // res is the right HTTP client
    }
});

In RX Java:

HttpEndpoint.getClient(discovery, record -> 
        record.getName().equalsIgnoreCase("my-http-service"),
        ar -> {
          if (ar.failed()) {
            message.reply("FAIL - no service");
          } else {
            HttpClient client = ar.result(); // Already the right type of object
            message.reply(result);
          }
});

It also works for service proxies, where you need to pass the class you expect to get:

EventBusService.getServiceProxy(discovery,
        record -> record.getName().equalsIgnoreCase("my-service"),
        HelloService.class, // <---- the RX Hello Service class
        ar -> {
          if (ar.failed()) {
            message.reply("FAIL - no service");
          } else {
            HelloService client = ar.result();
          }
});

Don’t ask, they seemed to have been generated by my IDE.
Remove the parameter on service type and service reference
Rename getService and getCachedService to getAs and cachedAs.
@cescoffier cescoffier merged commit 7ba800b into master Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

ServiceReference#get method does not rewrap the service
1 participant