Я пытаюсь перенаправить запросы в службу REST, обнаруженную Spring Cloud Eureka, через прокси Zuul.
#CandidateRESTAPI
@RestController
@RequestMapping(value = "/api/candidates")
public class CandidatRestAPI {
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<Candidate> createCandidat(@RequestBody Candidate candidate){
return new ResponseEntity<>(candidatService.addCandidat(candidate) , HttpStatus.OK);
}
@PutMapping(value = "/{id}" , produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Candidate> updateCandidat(@PathVariable(value = "id") int id , @RequestBody Candidate candidate){
return new ResponseEntity<>(candidatService.updateCandidat(id, candidate), HttpStatus.OK);
}
@DeleteMapping(value="/{id}" , produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<String> deleteCandidate(@PathVariable(value = "id") int id){
return new ResponseEntity<>(candidatService.deleteCandidat(id), HttpStatus.OK);
}
}
----------------------------------------------------
#Service Candidate : Application.properties
spring.application.name=candidat_service
eureka.client.service-url.default-zone=http://localhost:8761/eureka-server
eureka.client.register-with-eureka=true
#Eureka server : application.properties
spring.application.name=eureka-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
#Eureka server : Function
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
-----------------------------------------------------------
#ZuulProxy : application.properties
spring.application.name=zuul-gateway
server.port=8762
eureka.instance.prefer-ip-address=true
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.default-zone=http://localhost:8761/eureka-server
zuul.routes.job-service.path=/job_service/*
zuul.routes.job-service.service-id=job_service
zuul.routes.candidat-service.path=/candidat_service/*
zuul.routes.candidat-endpoint.service-id=candidat_service
zuul.routes.candidat-service.service-id=candidat_service
#ZuulProxy : function
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
Я ожидаю получить доступ к службе кандидата с помощью zuul, но у меня ошибка TIMEOUT:
Превышено время ожидания услуги кандидата и нет запасного варианта