您正在查看 Apigee Edge 文档。
前往 Apigee X 文档。 信息
本文档介绍了如何为 Apigee Edge 消息处理器配置 I/O 超时。
消息处理器上的 I/O 超时是指消息处理器在超时之前等待从后端服务器接收响应或等待套接字准备好向后端服务器写入请求的时间。
消息处理器 I/O 超时默认值为 55 seconds。此超时时间段适用于在 API 代理的目标端点配置和 ServiceCallout 政策中配置的后端服务器。
您可以根据需要,将消息处理器的 I/O 超时时间从默认值 55 seconds 增加或减少。可以在以下位置进行配置:
- 在 API 代理中
- 目标端点
- ServiceCallout 政策
- 在消息处理器上
以下属性用于控制消息处理器的 I/O 超时:
| 属性名称 | 位置 | 说明 |
|---|---|---|
io.timeout.millis
|
API 代理:
|
这是消息处理器执行以下操作的最长时间:
如果后端服务器在此超时期限内未做出响应,则消息处理器会超时。
默认情况下,此属性采用在消息处理器上为 如果使用特定 API 代理的新超时值修改此属性,则只会影响该 API 代理。 |
HTTPTransport.io.timeout.millis
|
消息处理器 |
这是消息处理器执行以下操作的最长时间:
如果后端服务器在此超时期限内未做出响应,则消息处理器会超时。 此属性适用于在此消息处理器上运行的所有 API 代理。
此属性的默认值为
您可以按照在消息处理器上配置 I/O 超时中的说明修改此属性,也可以通过在 API 代理级别设置 |
准备工作
在执行本文档中的步骤之前,请务必了解以下主题:
- 如果您不熟悉 I/O 超时,请参阅
TargetEndpoint 传输属性规范中的
io.timeout.millis属性说明。 - 如果您不熟悉如何为 Edge 私有云配置属性,请参阅 如何配置 Edge。
- 确保遵循 配置 I/O 超时的最佳实践中的建议。
在 API 代理中配置 I/O 超时
可以在以下 API 代理位置配置 I/O 超时:
- 目标端点
- ServiceCallout 政策
在 API 代理的目标端点中配置 I/O 超时
本部分介绍了如何在 API 代理的目标端点中配置 I/O 超时。
可以通过属性 io.timeout.millis 配置 I/O 超时,该属性表示以毫秒为单位的 I/O 超时值。
- 在 Edge 界面中,选择要配置新 I/O 超时值的特定 API 代理。
- 选择要修改的特定目标端点。
- 在
TargetEndpoint配置的<HTTPTargetConnection>元素下添加属性io.timeout.millis,并为其指定适当的值。 - 保存对 API 代理所做的更改。
例如,如需将 I/O 超时时间更改为 120 秒,请添加以下代码块:
<Properties>
<Property name="io.timeout.millis">120000</Property>
</Properties>由于 io.timeout.millis 属性以毫秒为单位,因此 120 秒的值为 120000。
以下示例展示了如何在 API 代理的目标端点配置中配置 I/O 超时:
使用后端服务器网址的目标端点配置示例
<TargetEndpoint name="default">
<HTTPTargetConnection>
<URL>https://mocktarget.apigee.net/json</URL>
<Properties>
<Property name="io.timeout.millis">120000</Property>
</Properties>
</HTTPTargetConnection>
</TargetEndpoint>使用目标服务器的目标端点配置示例
<TargetEndpoint name="default">
<HTTPTargetConnection>
<LoadBalancer>
<Server name="target1" />
<Server name="target2" />
</LoadBalancer>
<Properties>
<Property name="io.timeout.millis">120000</Property>
</Properties>
<Path>/test</Path>
</HTTPTargetConnection>
</TargetEndpoint>在 API 代理的 ServiceCallout 政策中配置 I/O 超时
本部分介绍了如何在 API 代理的 ServiceCallout 政策中配置 I/O 超时。可以通过 <Timeout> 元素或 io.timeout.millis 属性配置 I/O 超时。<Timeout> 元素和 io.timeout.millis 属性均表示以毫秒为单位的 I/O 超时值。
您可以使用以下方法之一在 ServiceCallout 政策中配置 I/O 超时:
<Timeout>元素。io.timeout.millis属性所定义)。
超时元素
如需使用 <Timeout> 元素在 ServiceCallout 政策中配置 I/O 超时,请执行以下操作:
- 在 Edge 界面中,选择要为 ServiceCallout 政策配置新 I/O 超时值的特定 API 代理。
- 选择要修改的特定 ServiceCallout 政策。
- 在
<ServiceCallout>配置下添加具有适当值的元素<Timeout>。例如,如需将 I/O 超时时间更改为 120 秒,请添加以下代码行:
<Timeout>120000</Timeout>
由于
<Timeout>元素以毫秒为单位,因此 120 秒的值为120000。以下示例展示了如何使用
<Timeout>元素在 ServiceCallout 政策中配置 I/O 超时:使用后端服务器网址的 ServiceCallout 政策配置示例
<ServiceCallout name="Service-Callout-1"> <DisplayName>ServiceCallout-1</DisplayName> <Timeout>120000</Timeout> <HTTPTargetConnection> <Properties/> <URL>https://mocktarget.apigee.net/json</URL> </HTTPTargetConnection> </ServiceCallout> - 保存对 API 代理所做的更改。
io.timeout.millis 属性
如需使用 io.timeout.millis 属性在 ServiceCallout 政策中配置 I/O 超时,请执行以下操作:
- 在 Edge 界面中,选择要为 ServiceCallout 政策配置新 I/O 超时值的特定 API 代理。
- 选择要修改的特定 ServiceCallout 政策。
- 在 TargetEndpoint 配置的
<HTTPTargetConnection>元素下添加属性io.timeout.millis,并为其指定适当的值。例如,如需将 I/O 超时时间更改为 120 秒,请添加以下代码块:
<Properties> <Property name="io.timeout.millis">120000</Property> </Properties>由于
io.timeout.millis属性以毫秒为单位,因此 120 秒的值为120000。以下示例展示了如何在 API 代理的目标端点配置中配置 I/O 超时:
使用后端服务器网址的 ServiceCallout 政策配置示例
<ServiceCallout name="Service-Callout-1"> <DisplayName>ServiceCallout-1</DisplayName> <HTTPTargetConnection> <Properties> <Property name="io.timeout.millis">120000</Property> </Properties> <URL>https://mocktarget.apigee.net/json</URL> </HTTPTargetConnection> </ServiceCallout>使用目标服务器的 ServiceCallout 政策配置示例
<ServiceCallout enabled="true" name="Service-Callout-1"> <DisplayName>ServiceCallout-1</DisplayName> <Response>calloutResponse</Response> <HTTPTargetConnection> <LoadBalancer> <Server name="target1" /> <Server name="target2" /> </LoadBalancer> <Properties> <Property name="io.timeout.millis">120000</Property> </Properties> <Path>/test</Path> </HTTPTargetConnection> </ServiceCallout> - 保存对 API 代理所做的更改。
在消息处理器上配置 I/O 超时
本部分介绍了如何配置消息处理器的 I/O 超时。
I/O 超时可以通过属性 HTTPTransport.io.timeout.millis 进行配置,该属性表示消息处理器组件上的 I/O 超时值(以毫秒为单位),使用令牌的语法如如何配置 Edge 中所述。
如需在消息处理器上配置 I/O 超时,请执行以下操作:
- 在消息处理器机器上,通过编辑器打开以下文件。如果该目录尚不存在,则创建该目录。
/opt/apigee/customer/application/message-processor.properties
例如,如需使用
vi打开文件,请输入以下命令:vi /opt/apigee/customer/application/message-processor.properties
- 在属性文件中添加一行,格式如下,并替换 TIME_IN_MILLISECONDS 的值:
conf_http_HTTPTransport.io.timeout.millis=TIME_IN_MILLISECONDS
例如,如需将消息处理器的 I/O 超时时间更改为 120 秒,请添加以下行:
conf_http_HTTPTransport.io.timeout.millis=120000
- 保存更改。
- 确保属性文件归
apigee用户所有,如下所示:chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
- 重启消息处理器,如下所示:
/opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
- 如果您有多个消息处理器,请在所有消息处理器上重复执行上述步骤。
验证消息处理器上的 I/O 超时
本部分介绍了如何验证是否已在消息处理器上成功修改 I/O 超时。
即使您使用令牌 conf_http_HTTPTransport.io.timeout.millis 在消息处理器上设置了 I/O 超时,您也需要验证实际属性 HTTPTransport.io.timeout.millis 是否已设置为新值。
- 在消息处理器机器上,在
/opt/apigee/edge-message-processor/conf目录中搜索属性HTTPTransport.io.timeout.millis,并检查该属性是否已设置为新值,如下所示:grep -ri "HTTPTransport.io.timeout.millis" /opt/apigee/edge-message-processor/conf
- 如果成功在消息处理器上设置了新的 I/O 超时值,则上述命令会在
http.properties文件中显示新值。 - 如果您仍然看到属性
HTTPTransport.io.timeout.millis的旧值,请验证您是否已正确按照在消息处理器上配置 I/O 超时中所述的所有步骤操作。如果您错过了任何步骤,请再次正确重复所有步骤。 - 如果您仍然无法修改 I/O 超时,请与 Apigee Edge 支持团队联系。
将 I/O 超时时间配置为 120 秒后,上述命令的示例结果如下所示:
/opt/apigee/edge-message-processor/conf/http.properties:HTTPTransport.io.timeout.millis=120000
在上面的示例输出中,请注意,属性 HTTPTransport.io.timeout.millis 已在 http.properties 中设置为新值 120000。这表示已成功将消息处理器上的 I/O 超时时间配置为 120 秒。