I have java code to insert services into my consul sevice, using spring-cloud-starter-consul-all and java code like this:
if (response.getValue().isEmpty()) {
NewService service = new NewService();
service.setAddress("serverhere.com");
service.setPort(8200);
service.setId("servideId");
service.setName("serviceName");
client.agentServiceRegister(service);
}
I need to add also parameters, or path, like:
http://serverhere.com:8080/parameter1/parameter2.
I do not know where to insert the parameters: /parameter1/parameter2.
I have tried adding this code:
//HealthCheck
NewService.Check serviceCheck = new NewService.Check();
serviceCheck.setHttp(service.getHealthCheck());
serviceCheck.setInterval(healthCheckInterval);
serviceCheck.setTimeout(healthCheckTimeout);
//Path
NewService.Check serviceCheckPath = new NewService.Check();
serviceCheckPath.setScript("/parameter1/parameter2");
serviceCheckPath.setInterval(healthCheckInterval);
List<Check> serviceCheckList = new ArrayList();
serviceCheckList.add(serviceCheck);
serviceCheckList.add(serviceCheckPath);
newService.setChecks(serviceCheckList);
client.agentServiceRegister(newService);
I get this error: OperationException(statusCode=400, statusMessage='Bad Request', statusContent='Request decode failed: json: unknown field "Script"')
Could you help me to find the appropiate field to save path related to a service. Thank you in advance.
Consul service definitions can only contain IP and port information. The catalog does not have a first class method for storing HTTP path information.
You could potentially use the Meta
field of the service registration to store this info in a path
key. You would then need to write logic in your applications to perform the service discovery using the HTTP API, and concatenate the IP, port, and path from the meta field to form the full URL.