我正在尝试通过Zuul代理将请求路由到Spring Cloud Eureka发现的REST服务。
#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访问候选服务,但是我遇到了超时错误:
候选服务超时,没有可用的后备