0

我构建了一个 spring 云服务,包含 eureka、user-service(spring-data-rest user api) 和一个 feign-client 服务。

在假装客户端中:

@FeignClient("useraccount")
public interface UserFeign {
    @RequestMapping(method=RequestMethod.POST,value="/users",consumes = "application/json")
    void createUser(@RequestBody User user);
    @RequestMapping(method=RequestMethod.DELETE,value="/users/{id}")
    void delById (@PathVariable("id") String id);

我想通过调用 user-service api 来实现在 feign-client 中删除和存储用户。所以,我创建了一个休息控制器(js 向他们传输数据):

@Autowired
    private UserFeign userFeign;

//save controller 

@RequestMapping(method = RequestMethod.POST, value = "/property/register")
    public  ResponseEntity<?>  createUser(@RequestBody User user) {
            userSaveFeign.createUser(user);
            return   ResponseEntity.ok();
    }


// and delete controller 

@RequestMapping(method = RequestMethod.DELETE, value = "/property/{id}")
    public String hello(@PathVariable("id") String id){
            userSaveFeign.delById(id);
        }
        return "hello";
    }

但它总是遇到错误:

2016-04-16 20:05:41.162   .DynamicServerListLoadBalancer     DynamicServerListLoadBalancer for client useraccount initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=useraccount,current list of Servers=[192.168.1.101:useraccount:d3fb971b6fe30dc5e9cbfdf0e713cd12],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;  Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:192.168.1.101:useraccount:d3fb971b6fe30dc5e9cbfdf0e713cd12;    Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 08:00:00 CST 1970;  First connection made: Thu Jan 01 08:00:00 CST 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@19c54b19
2016-04-16 20:05:41.836[2m[nio-8002-exec-4][36mo.a.c.c.C.[.[.[/].[dispatcherServlet]  [0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.netflix.hystrix.exception.HystrixRuntimeException: createUser timed-out and no fallback available.] with root cause

java.util.concurrent.TimeoutException: null
    at com.netflix.hystrix.AbstractCommand$9.call(AbstractCommand.java:600) ~[hystrix-core-1.5.1.jar:1.5.1]
    at com.netflix.hystrix.AbstractCommand$9.call(AbstractCommand.java:580) ~[hystrix-core-1.5.1.jar:1.5.1]
    at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:99) ~[rxjava-1.0.14.jar:1.0.14]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.14.jar:1.0.14]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.14.jar:1.0.14]
    at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:955) ~[hystrix-core-1.5.1.jar:1.5.1]
    at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41) ~[hystrix-core-1.5.1.jar:1.5.1]
    at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37) ~[hystrix-core-1.5.1.jar:1.5.1]
    at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57) ~[hystrix-core-1.5.1.jar:1.5.1]
    at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.tick(AbstractCommand.java:972) ~[hystrix-core-1.5.1.jar:1.5.1]
    at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99) ~[hystrix-core-1.5.1.jar:1.5.1]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_40]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[na:1.8.0_40]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_40]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[na:1.8.0_40]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_40]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_40]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]

也许上面的存储和删除方法有问题,但是谁能告诉我正确的或更好的?

4

2 回答 2

5

看起来您的 Hystrix 命令正在超时。假设您没有专门的任何 Hystrix 命令(如您的帖子中未提及的那样),Hystrix 是 Feign Client 中免费包含的一种断路器技术。您可以使用以下方法禁用此功能:

feign.hystrix.enabled=false

(您可以在http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html#spring-cloud-feign-hystrix找到有关 Feign-Hystrix 集成的更多信息)

这不会解决某些事情需要很长时间才能完成的路线。您将需要调试并找出挂起的内容。它可能是您的 Feign 客户端指向的实际端点正在连接但没有响应,尽管我通常希望在这种情况下看到特定的连接超时异常。

于 2016-04-20T08:51:58.790 回答
0

这不是实际的异常,您应该找到它超时的原因。启用日志记录,然后您可以看到它失败的原因:

import org.springframework.context.annotation.Bean;

import feign.Logger;

public class FeignConfiguration {

    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }
}

还要查看服务器是否完全解析。您的日志应如下所示:

DynamicServerListLoadBalancer for client auth-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=auth-service,current list of Servers=[192.168.2.243:7277],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:192.168.2.243:8180;    Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 06:00:00 BDT 1970;  First connection made: Thu Jan 01 06:00:00 BDT 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@9481a7c
于 2016-10-24T08:31:46.273 回答