Last active
December 15, 2015 23:18
-
-
Save gdusbabek/5338824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.rackspacecloud</groupId> | |
<artifactId>service-registry-client</artifactId> | |
<version>2.0.1-SNAPSHOT</version> | |
</dependency> | |
<dependency> | |
<groupId>com.rackspacecloud</groupId> | |
<artifactId>service-registry-curator</artifactId> | |
<version>2.0.1-SNAPSHOT</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ServiceDiscovery<ExampleService> discovery = RSRServiceDiscoveryBuilder | |
.builder(Class.forName("your classname goes here") | |
.withUser("RAX_USER") | |
.withApiKey("RAX_KEY") | |
.withApiUrl("https://dfw.registry.api.rackspacecloud.com/v1.0") | |
.build(); | |
discovery.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.rackspacecloud.client.service_registry.curator.Meta; | |
import com.rackspacecloud.client.service_registry.objects.Service; | |
// this one will work with either Curator or Rackspace registries. | |
@JsonRootName("service") | |
public class SampleService { | |
// you can have any fields you want. These ones just happen to mimic the fields on a typical curator service. | |
@Meta private String payload; | |
@Meta private int port = 0; | |
@Meta private int sslPort = 0; | |
@Meta private String name = ""; | |
@Meta private String id; | |
// todo: constructor, getters, setters, etc. | |
// part of an implicit interface | |
public static ServiceInstance<SampleService> convert(SampleService svc) throws Exception { | |
return ServiceInstance.<SampleService>builder() | |
.name(svc.getName()) | |
.payload(svc) | |
.port(svc.getPort()) | |
.id(svc.getId()) | |
.sslPort(svc.getPort()) | |
.build(); | |
} | |
// also part of an implicit interface. | |
public static ServiceInstance<SampleService> convert(Service svc) throws Exception { | |
SampleService exampleService = new SampleService(svc.getMetadata().get("id"), | |
svc.getMetadata().get("name"), | |
svc.getMetadata().get("payload"), | |
Integer.parseInt(svc.getMetadata().get("port")), | |
Integer.parseInt(svc.getMetadata().get("sslPort"))); | |
return convert(exampleService); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment