这两天在把原来的项目迁移到spring cloud上,微服务之间的数据传输使用protobuf。
码了几天的代码。重要准备上线测试下微服务之间的接口调用功能,但是在用feign调用数据库代理接口时,总是报一个错误,在这记录下。
feign客户端接口定义如下:
@FeignClient(name = "db-proxy")
public interface RemoteRestFull {
@RequestMapping(value = "/getUser")
User.UserInfoRsp getUserInfo(@RequestBody User.UserInfoReq req);
}
服务端接口实现如下:
@RestController
public class UserRestFull {
@RequestMapping("/getUser")
public User.UserInfoRsp getUserInfo(@RequestBody User.UserInfoReq req) {
.......
}
}
服务端具体代码实现就省略了。
服务启动后,使用测试代码测试连接,发送消息。在feign接口调用时,出现下面的错误:
因为涉及到具体的类报错,省略了一些信息。。。
[WARN ][2021-01-04 14:10:38][DefaultChannelPipeline.java:1152]:onUnhandledInboundException - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
feign.codec.EncodeException: Error converting request body
at org.springframework.cloud.openfeign.support.SpringEncoder.encode(SpringEncoder.java:119) ~[spring-cloud-openfeign-core-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
at org.springframework.cloud.openfeign.support.PageableSpringEncoder.encode(PageableSpringEncoder.java:101) ~[spring-cloud-openfeign-core-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:380) ~[feign-core-10.10.1.jar!/:?]
at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:232) ~[feign-core-10.10.1.jar!/:?]
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:84) ~[feign-core-10.10.1.jar!/:?]
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) ~[feign-core-10.10.1.jar!/:?]
at com.sun.proxy.$Proxy93.getUser(Unknown Source) ~[?:?]
......................
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-all-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-all-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-all-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) [netty-all-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) [netty-all-4.1.54.Final.jar!/:4.1.54.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandl

在将项目迁移到Spring Cloud并使用protobuf进行微服务间数据传输时,遇到Feign调用数据库代理接口报错。错误源于feign无法处理protobuf类参数。通过分析日志,发现是AbstractJackson2HttpMessageConverter转换问题。为解决此问题,需在feign客户端和服务端分别配置protobuf的HttpMessageConverter,并在pom中正确引入openfeign依赖。

1789

被折叠的 条评论
为什么被折叠?



