无法连接到命令指标流。在Eureka管理员中

时间:2019-01-22 09:40:42

标签: spring spring-cloud hystrix api-gateway

我遇到错误-无法连接到Command Metric Stream。

我已经使用启动版本 2.1.2.RELEASE 和云版本 Greenwich.RC2 https://howtodoinjava.com/spring-cloud/microservices-monitoring/实施了enter image description here中的api-gateway-service。 / p>

enter image description here

pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>

    <!-- Hystrix -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </repository>
</repositories>

application.yml

spring:
  application:
    name: api-gateway

server:
  port: 8010

eureka:
  instance:
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 2
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
    healthcheck:
      enabled: true
    lease:
      duration: 5

logging:
  level:
    com.self.sprintboot.learning.apigateway: DEBUG

management:
  endpoints:
    web:
      exposure:
        exclude: hystrix.stream, info, health
      base-path: /

EmployeeController.java

@RestController
public class EmployeeController {
    private static final String URL = "http://employee-service/findEmployeeDetails/{employeeid}";
    @Autowired
    private RestTemplate restTemplate;

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @GetMapping("/employeeDetails/{employeeid}")
    @HystrixCommand(fallbackMethod = "fallbackMethod")
    public String getStudents(@PathVariable int employeeid) {
        System.out.println("Getting Employee details for " + employeeid);

        ResponseEntity<String> responseEntity = restTemplate.exchange(URL, HttpMethod.GET, null,
                new ParameterizedTypeReference<String>() {
                }, employeeid);
        String response = responseEntity.getBody();
        System.out.println("Response Body " + response);
        return "Employee Id -  " + employeeid + " [ Employee Details " + response + " ]";
    }

    private String fallbackMethod(int employeeid) {
        return "Fallback response:: No employee details available temporarily";
    }
}

ApiGatewayApplication.java

@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ApiGatewayApplication {

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

Context

1 个答案:

答案 0 :(得分:0)

exposure部分的management小节中,将exclude更改为include