Comments (10)
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.
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.
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.
OK- I've added this. There is now an optional UriSpec in the ServiceInstance. Thanks for the suggestion.
from curator.
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.
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.
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.
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.
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.
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)
- java.nio.channels.CancelledKeyException HOT 1
- java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.build HOT 4
- adding nodes to zookeeper from local properties through archaius HOT 1
- InterProcessMutex is not releasing when called inside a future's onSuccess function. HOT 1
- Curator's Watch triggered two times for the same notification HOT 3
- Curator integration with Exhibitor-values to be provided for ExhibitorEnsembleProvider arguments HOT 1
- What's the plan for releasing changes to this? HOT 3
- org.apache.zookeeper.KeeperException$NodeExistsException: KeeperErrorCode = NodeExists HOT 3
- curator use this.client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path, data); but I find zk didnot have this node. HOT 2
- Link in wiki is broken HOT 1
- Examples Link in Table of Contents leads to 404 HOT 2
- NoSuchMethodError exception HOT 2
- Curator connecting to a secured SASL zookeeper HOT 1
- Background operation retry gave up HOT 1
- ..
- The result of event.getPath() in BackgroundCallback confused me
- Missing method declaration addAuthInfo
- TestingServer cannot start, it always throw FailedServerStartException
- curator 5.3 connect docker zookeeper cluster
- the parent node never delete cause thousands of parent node
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curator.