0

我有这个声明性客户端:

@Retryable(attempts = "5", multiplier = "1.2")
@Client("\${client-url}")
@Headers(
    Header(name = USER_AGENT, value = "Micronaut Http Client"),
)
interface MyApiClient {

    @Get("/locations?location={location}")
    suspend fun validationLocation(@QueryValue location: String) : LocationResponse
}

我已将客户端超时设置为 30 秒:

micronaut:
 http:
    client:
      read-timeout: 30s

随机我得到:

Client <package> received HTTP error response: Read Timeout
    2021-08-02T23:09:13.069278169Z io.micronaut.http.client.exceptions.ReadTimeoutException: Read Timeout
    2021-08-02T23:09:13.069283269Z  at io.micronaut.http.client.exceptions.ReadTimeoutException.<clinit>(ReadTimeoutException.java:26)
    2021-08-02T23:09:13.069287569Z  at io.micronaut.http.client.netty.DefaultHttpClient$11.exceptionCaught(DefaultHttpClient.java:2301)
    2021-08-02T23:09:13.069291069Z  at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
    2021-08-02T23:09:13.069306269Z  at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
    2021-08-02T23:09:13.069309969Z  at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:273)
    2021-08-02T23:09:13.069313269Z  at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireExceptionCaught(CombinedChannelDuplexHandler.java:424)
    2021-08-02T23:09:13.069316669Z  at io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:92)
    2021-08-02T23:09:13.069319769Z  at io.netty.channel.CombinedChannelDuplexHandler$1.fireExceptionCaught(CombinedChannelDuplexHandler.java:145)
    2021-08-02T23:09:13.069323069Z  at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:143)
    2021-08-02T23:09:13.069326169Z  at io.netty.channel.CombinedChannelDuplexHandler.exceptionCaught(CombinedChannelDuplexHandler.java:231)
    2021-08-02T23:09:13.069329469Z  at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
    2021-08-02T23:09:13.069332669Z  at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
    2021-08-02T23:09:13.069335869Z  at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:273)
    2021-08-02T23:09:13.069339069Z  at io.netty.handler.timeout.ReadTimeoutHandler.readTimedOut(ReadTimeoutHandler.java:98)
    2021-08-02T23:09:13.069342369Z  at io.netty.handler.timeout.ReadTimeoutHandler.channelIdle(ReadTimeoutHandler.java:90)

这种非常烦人的行为可能是什么原因造成的?

4

2 回答 2

0

这个问题似乎与同一问题有关:Micronaut ReadTimeoutException

显然配置没有注入。您可能必须以编程方式设置它。

于 2021-08-03T05:59:26.757 回答
0

显然,suspend从函数中删除并使其返回 aSingle<LocationResponse>会使超时消失。

于 2021-08-04T01:30:30.473 回答