我构建了一个spring spring服务,包含eureka,用户服务(spring-data-rest用户api)和feign-client服务。
假装客户:
use byteWriter = new BinaryWriter(new MemoryStream(bytes))
[1;2;3] |> List.iter(fun s -> byteWriter.Write(int16(s)))
byteWriter.Close() // is this needed?
我想通过调用user-service api来实现在feign-client中删除和存储用户。所以,我创建了一个休息控制器(js将数据传输给他们):
@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);
但总是遇到错误:
@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";
}
上述存储和删除方法可能存在问题,但谁可以告诉我正确或更好?
答案 0 :(得分:4)
看起来你的Hystrix Command正在超时。假设您没有特别使用任何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客户端指向的实际端点正在连接但没有响应,尽管在这种情况下我通常希望看到特定的连接超时异常。
答案 1 :(得分:0)
这不是实际的例外,你应该找到它的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