use of io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint in project gravitee-gateway by gravitee-io.
the class EndpointDiscoveryConsulVerticle method handleRegisterService.
private void handleRegisterService(Api api, Service service) {
Endpoint createdEndpoint = createEndpoint(service);
Set<Endpoint> managedEndpoints = api.getProxy().getEndpoints();
// Get previous endpoint reference
Endpoint preEndpoint = managedEndpoints.stream().filter(createdEndpoint::equals).findAny().orElse(null);
// Endpoint does not exist (according to its name)
if (preEndpoint == null) {
LOGGER.info("Register a new endpoint from Consul.io: id[{}] name[{}]", service.getId(), service.getName());
managedEndpoints.add(createdEndpoint);
} else if (preEndpoint instanceof DiscoveredEndpoint) {
// Update it only if target has been changed
DiscoveredEndpoint dynamicEndpoint = (DiscoveredEndpoint) preEndpoint;
if (!createdEndpoint.getTarget().equals(dynamicEndpoint.getTarget())) {
LOGGER.info("Update an existing endpoint from Consul.io: id[{}] name[{}] target[{}]", service.getId(), service.getName(), createdEndpoint.getTarget());
managedEndpoints.remove(preEndpoint);
managedEndpoints.add(createdEndpoint);
}
}
}
use of io.gravitee.gateway.services.endpoint.discovery.consul.endpoint.DiscoveredEndpoint in project gravitee-gateway by gravitee-io.
the class EndpointDiscoveryConsulVerticle method createEndpoint.
private Endpoint createEndpoint(Service service) {
String address = service.getAddress();
if (address == null || address.trim().isEmpty()) {
address = service.getNodeAddress();
}
DiscoveredEndpoint endpoint = new DiscoveredEndpoint("consul:" + service.getId(), "http://" + address + ':' + service.getPort());
endpoint.setHttpClientOptions(new HttpClientOptions());
return endpoint;
}
Aggregations