Skip to content

Instantly share code, notes, and snippets.

@gdusbabek
Last active December 15, 2015 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdusbabek/5338824 to your computer and use it in GitHub Desktop.
Save gdusbabek/5338824 to your computer and use it in GitHub Desktop.
<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>
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();
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