这是我使用 PCF Dev 的第一个微服务。我创建了以下 Eureka Server App。
@EnableEurekaServer
@SpringBootApplication
public class EurekaServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication.class, args);
}
}
以下是 eureka-server 服务的属性
eureka-service.register-with-eureka=false
eureka-service.fetch-registry=false
eureka-service.defaultZone=http://eureka-service.local.pcfdev.io/
eureka-service.logging.level.com.netflix.eureka=OFF
eureka-service.logging.level.com.netflix.discovery=OFF
下面是尤里卡客户端服务
@EnableDiscoveryClient
@SpringBootApplication
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}
@RestController
class ServiceInstanceRestController {
@Autowired
private DiscoveryClient discoveryClient;
@RequestMapping("/service-instances/{applicationName}")
public List<ServiceInstance> serviceInstancesByApplicationName(@PathVariable String applicationName) {
return this.discoveryClient.getInstances(applicationName);
}
}
以下是 eureka-client 服务的属性
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.defaultZone=http://eureka-client.local.pcfdev.io/
eureka.client.logging.level.com.netflix.eureka=ON
eureka.client.logging.level.com.netflix.discovery=ON
我已经在本地运行的 PCF Dev 实例上部署了微服务
当我在本地将服务器和客户端作为 Java 应用程序运行时,我可以看到来自service-instances/eureka-client端点的响应。但是当我尝试调用以下端点时,我得到一个空数组
http://eureka-client.local.pcfdev.io/service-instances/eureka-client
当我尝试访问 eureka-service 时,使用 URL
http://eureka-service.local.pcfdev.io/
我得到以下回复:
This site can’t be reached eureka-service.local.pcfdev.io refused to connect.
Search Google for eureka service local pcfdev io
ERR_CONNECTION_REFUSED
提前致谢。
编辑-1:
根据@Barath 的评论,我修改了客户端应用程序的 application.properties 文件,如下所示,但问题仍未解决。之前,我在 application.properties 文件中错误地引用了客户端应用程序名称。
eureka-client.register-with-eureka=true
eureka-client.fetch-registry=true
eureka-client.serviceUrl.defaultZone=http://eureka-client.local.pcfdev.io/
eureka-client.logging.level.com.netflix.eureka=ON
eureka-client.logging.level.com.netflix.discovery=ON
客户端的 bootstrap.properties 文件具有以下条目:
spring.application.name=eureka-client
服务器的 bootstrap.properties 文件具有以下条目:
spring.application.name=eureka-service
编辑-2
服务器:https ://github.com/abnig/eureka-service 客户端:https ://github.com/abnig/eureka-client