use of org.apache.curator.x.discovery.UriSpec in project oozie by apache.
the class FixedJsonInstanceSerializer method deserialize.
@Override
public ServiceInstance<T> deserialize(final byte[] pBytes) throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(pBytes);
final JsonNode rootNode = mMapper.readTree(bais);
final ServiceInstanceBuilder<T> builder = ServiceInstance.builder();
{
final String address = getTextField(rootNode, "address");
if (address != null) {
builder.address(address);
}
}
{
final String id = getTextField(rootNode, "id");
if (id != null) {
builder.id(id);
}
}
{
final String name = getTextField(rootNode, "name");
if (name != null) {
builder.name(name);
}
}
{
final Integer port = getIntegerField(rootNode, "port");
if (port != null) {
builder.port(port);
}
}
{
final Integer sslPort = getIntegerField(rootNode, "sslPort");
if (sslPort != null) {
builder.sslPort(sslPort);
}
}
{
final Long registrationTimeUTC = getLongField(rootNode, "registrationTimeUTC");
if (registrationTimeUTC != null) {
builder.registrationTimeUTC(registrationTimeUTC);
}
}
{
final T payload = getObject(rootNode, "payload", mPayloadClass);
if (payload != null) {
builder.payload(payload);
}
}
{
final ServiceType serviceType = getObject(rootNode, "serviceType", ServiceType.class);
if (serviceType != null) {
builder.serviceType(serviceType);
}
}
{
final UriSpec uriSpec = getObject(rootNode, "uriSpec", UriSpec.class);
if (uriSpec != null) {
builder.uriSpec(uriSpec);
}
}
return builder.build();
}
use of org.apache.curator.x.discovery.UriSpec in project microservices by pwillhan.
the class Zookeeper method register.
public void register() {
CuratorFramework curator = CuratorFrameworkFactory.newClient(host + ":" + port, new RetryNTimes(3, 3000));
curator.start();
try {
final ServiceInstance<Object> serviceInstance = ServiceInstance.builder().uriSpec(new UriSpec("{scheme}://{address}:{port}")).address(getIp()).port(getPort()).name("geolocation").build();
final ServiceDiscovery<Object> serviceDiscovery = ServiceDiscoveryBuilder.builder(Object.class).basePath("com.packt.microservices").client(curator).thisInstance(serviceInstance).build();
serviceDiscovery.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
serviceDiscovery.unregisterService(serviceInstance);
} catch (Exception e) {
System.err.println("Error while unregistering service in Zookeeper. Details: " + e.getMessage());
e.printStackTrace();
}
}));
} catch (Exception e) {
System.err.println("Error while registering service in Zookeeper. Details: " + e.getMessage());
e.printStackTrace();
}
}
Aggregations