在PCF开发人员上无法获得Eureka客户服务

时间:2018-10-20 16:29:15

标签: netflix-eureka pcf

这是我使用PCF开发人员的第一个微服务。我创建了以下Eureka Server应用程序。

@EnableEurekaServer
@SpringBootApplication
public class EurekaServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServiceApplication.class, args);
    }
}

下面是eureka服务器服务的属性

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

下面是eureka客户端服务

@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实例上部署了微服务

PCF Dev Snapshot

当我在本地将服务器和客户端作为Java应用程序运行时,我看到的响应来自 service-instances / eureka-client 端点。但是当我尝试调用以下端点时会得到一个空数组

http://eureka-client.local.pcfdev.io/service-instances/eureka-client

当我尝试使用URL访问eureka服务时

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

Edit-2

服务器:https://github.com/abnig/eureka-service 客户:https://github.com/abnig/eureka-client

1 个答案:

答案 0 :(得分:1)

在eureka服务器和客户端中定义的属性如下所述

eureka服务器

eureka:
  instance:
    hostname: eureka-service.local.pcfdev.io
  client:
    fetch-registry: false
    register-with-eureka: false

eureka客户端

eureka:
  client:
    serviceUrl:
      defaultZone: https://eureka-service.local.pcfdev.io/eureka
    register-with-eureka: true
    fetch-registry: true

请参考spring-cloud-native供参考