Giter Site home page Giter Site logo

Comments (10)

Randgalt avatar Randgalt commented on June 16, 2024

Yeah, that could be useful. Of course, people are free to put that in the payload of the service. Protocol is so service specific, though; I can't imagine it being optional. i.e. it's implicit in the service itself the protocol to use. Can you think of an example where that's not true?

from curator.

gsingers avatar gsingers commented on June 16, 2024

Yeah, I can't think of a place where it's not part of it and I did work around it now by using payloads.

I'm not sure how useful it is for others, but we are basically ripping apart URI's to put them into ServiceDiscovery. Perhaps it makes sense to simply add native support for a URI? I've been trying to think of cases for ServiceDiscovery where one couldn't (or wouldn't want to) address a service as a URI. Naturally, we could keep the existing, too. (Just a suggestion)

Here's my code for registration:
public void registerService(ServiceType serviceType, URI endpoint) {
try {
ServiceInstanceBuilder builder = ServiceInstance.builder();
Map payload = new HashMap();
payload.put("scheme", endpoint.getScheme());
payload.put("path", endpoint.getPath());
ServiceInstance service = builder
.name(serviceType.name())
.address(endpoint.getHost())
.port(endpoint.getPort())
.payload(payload)
.build();
log.info("Registering Service: " + service);
discovery.registerService(service);
//create a provider for this service
ServiceProvider provider = discovery.serviceProviderBuilder()
.serviceName(serviceType.name()).providerStrategy(strategy).build();
provider.start();
providers.put(serviceType, provider);

} catch (Exception e) {
  throw new RuntimeException("Could not register service '" + serviceType + "'", e);
}

}

//Note, the ServiceType here is not the same ServiceType in curator, I just coincidentally named it as such.

Of note, I am using the Map there for the payload b/c I always feel like, with Jackson, that I am fitting with the proxy objects that it returns back. I tried Jackson annotations, but didn't seem to work in my cursory glance at them.

from curator.

Randgalt avatar Randgalt commented on June 16, 2024

I considered something like URI at first. But, you wouldn't want to repeat the host and port. It would need to be some kind of URI specification. e.g. "{protocol}://{host}:{port}/foo/bar/snafu". Is this generally useful? I don't want to put metadata in the object that isn't horizontally useful.

from curator.

Randgalt avatar Randgalt commented on June 16, 2024

OK- I've added this. There is now an optional UriSpec in the ServiceInstance. Thanks for the suggestion.

from curator.

gsingers avatar gsingers commented on June 16, 2024

Randgalt,

Finally coming back around to this. I guess I am a bit lost on the change here. What does the UriSpec actually do? I'm trying to register a specific service at a specific host and port, what good does the variable stuff do ({protocol}, {host}, etc.)? I would just like to be able to pass in a URI and register my service at that URI. I don't get the "repeat the host and port" part.

from curator.

Randgalt avatar Randgalt commented on June 16, 2024

I wanted something more flexible that a raw string. Thus UriSpec. However, you can pass in a straight URI if you like (i.e. no replacement tokens).

from curator.

gsingers avatar gsingers commented on June 16, 2024

If I do:
UriSpec spec = new UriSpec("http://localhost:8888/foo/bar");
ServiceInstance service = builder.uriSpec(spec).build();

I get an NPE on the Precondition saying name must not be null. In looking at the test, I still don't get what it accomplishes over just taking in an actual URI and registering all the parts of it (see my original example where I have to overload the payload functionality to include the scheme and path.)

from curator.

Randgalt avatar Randgalt commented on June 16, 2024
I get an NPE on the Precondition saying name must not be null

That's a bug. I'll work on a fix.

from curator.

Randgalt avatar Randgalt commented on June 16, 2024
I still don't get what it accomplishes over just taking in an actual URI and registering all the parts of it (see my original example where I have to overload the payload functionality to include the scheme and path.)

It allows for parameterized building of the URL based on the ServiceInstance. For example, the UriSpec could be stored in a properties file and applied to any Service Instance to generate the correct URI.

from curator.

Randgalt avatar Randgalt commented on June 16, 2024
If I do: UriSpec spec = new UriSpec("http://localhost:8888/foo/bar"); ServiceInstance service = builder.uriSpec(spec).build(); I get an NPE on the Precondition saying name must not be null.

This has nothing to do with the UriSpec. All services must have a name (and an ID). Change the code to this and it works:

builder.name("test").id("id").uriSpec(spec).build()

from curator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.