Я получаю следующий код от: https://howtodoinjava.com/spring-cloud/microservices-monitoring/ от Мониторинг микросервисов с помощью Hystrix, Eureka admin и Spring boot admin .
Похоже, что URL-адрес Spring Boot Admin не загружает приложение, а панель продолжает вращаться.
Ошибка:
java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH]
at org.apache.coyote.AsyncStateMachine.asyncError(AsyncStateMachine.java:440) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:512) [tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.coyote.Request.action(Request.java:430) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:382) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:239) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:241) [tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) [tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-embed-core-9.0.14.jar:9.0.14]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.14.jar:9.0.14]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_171]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.14.jar:9.0.14]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
Эврика-сервер
application.yml
server:
port: ${PORT:8761}
eureka:
client:
register-with-eureka: false
fetch-registry: false
registry-fetch-interval-seconds: 5
serviceUrl:
defaultZone: ${DISCOVERY_URL:http://localhost:8761}/eureka/
instance:
lease-expiration-duration-in-seconds: 10
#A different context path for admin server has been provided not conflicting with eureka
spring:
boot:
admin:
context-path: /admin
EurekaServerApplication.java
@SpringBootApplication
@EnableEurekaServer
@EnableAdminServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
* +1032 * апи-шлюз
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: "*"
# base-path: /
turbine:
app-config: WRITING,READING
cluster-name-expression: new String('default')
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);
}
}
работник-служба
application.yml
spring:
application:
name: employee-service
server:
port: 8011
eureka:
instance:
lease-expiration-duration-in-seconds: 5
lease-renewal-interval-in-seconds: 2
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
healthcheck:
enabled: true
lease:
duration: 5
EmployeeServiceApplication.java
@SpringBootApplication
public class EmployeeServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EmployeeServiceApplication.class, args);
}
}