java.lang.IllegalStateException:调用[asyncError()]对于具有异步状态[MUST_DISPATCH]的请求无效

时间:2019-01-23 08:27:33

标签: spring-cloud hystrix spring-boot-admin

我正在跟踪使用Hystrix,Eureka管理员和Spring boot管理员监控微服务的https://howtodoinjava.com/spring-cloud/microservices-monitoring/中的代码。

Spring Boot Admin URL似乎没有加载应用程序,并且栏杆不断旋转。

错误:

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]

enter image description here

eureka服务器 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);
    }
}

api网关 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);
    }
}

0 个答案:

没有答案