我遇到错误-无法连接到Command Metric Stream。
我已经使用启动版本 2.1.2.RELEASE 和云版本 Greenwich.RC2 从https://howtodoinjava.com/spring-cloud/microservices-monitoring/实施了中的api-gateway-service
。 / p>
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);
}
}
答案 0 :(得分:0)
在exposure
部分的management
小节中,将exclude
更改为include
。