Spring cloud 如何实现spring外贴和删除

Spring cloud 如何实现spring外贴和删除,spring-cloud,spring-cloud-feign,Spring Cloud,Spring Cloud Feign,我构建了一个spring云服务,包含eureka、用户服务(SpringDataRESTUserAPI)和一个外部客户端服务 在外国客户中: @FeignClient("useraccount") public interface UserFeign { @RequestMapping(method=RequestMethod.POST,value="/users",consumes = "application/json") void createUser(@RequestBo

我构建了一个spring云服务,包含eureka、用户服务(SpringDataRESTUserAPI)和一个外部客户端服务

在外国客户中:

@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);
我想通过调用用户服务api来实现在外部客户机中删除和存储用户。因此,我创建了一个rest控制器(js向它们传输数据):


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

您的Hystrix命令似乎超时了。假设您没有任何特定的Hystrix命令(您的帖子中没有提到),Hystrix是一种断路器技术,它免费提供给外国客户机。您可以通过以下方式禁用此功能:

feign.hystrix.enabled=false
(您可以在网站上找到有关Faign Hystrix integration的更多信息)


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

您的Hystrix命令似乎超时了。假设您没有任何特定的Hystrix命令(您的帖子中没有提到),Hystrix是一种断路器技术,它免费提供给外国客户机。您可以通过以下方式禁用此功能:

feign.hystrix.enabled=false
(您可以在网站上找到有关Faign Hystrix integration的更多信息)


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

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

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

这不是实际的例外情况,您应该找到其timedout的原因。启用日志记录,然后您可以看到它失败的原因:

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