问题
The documentation at Camel HTTP4 is quite clear that you can set the following options for the HTTP4 component: connectionRequestTimeout, connectTimeout, and socketTimeout.
However, these are listed as general component options, not query options in the documentation (and are ignored if set as query options -- they just get passed onto the HTTP endpoint when called). So I'm not sure how to set them. The HTTPComponent class does not seem to have any setter methods for these options.
The documentation does have a section Using client timeout - SO_TIMEOUT, that links to unit test source where they set httpClient.soTimeout as a query option. However, when I try that I get an error:
Failed to resolve endpoint: https4://myhost/myapi/v1?bridgeEndpoint=true&httpClient.soTimeout=1000 due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{soTimeout=1000}
回答1:
It turns out that the documentation isn't quite right. All of those timeout parameters can be set via query param options, but they need to be prefixed with httpClient. . Here is what worked for me:
?httpClient.connectTimeout=10000&httpClient.connectionRequestTimeout=10000&httpClient.socketTimeout=30000
I verified by testing with ridiculously small values (1 ms) and it produced "read timed out" errors.
It looks the availble options for httpClient are the setter values on RequestConfig.Builder.
来源:https://stackoverflow.com/questions/65723470/how-to-set-camel-http4-connection-timeout-options