您正在查看的是 Apigee Edge 文档。
转到 Apigee X 文档。 信息
本文档介绍如何为 Apigee Edge Message Processors 配置 I/O 超时。
消息处理器上的 I/O 超时表示消息处理器在超时之前等待接收来自后端服务器的响应或套接字准备好向后端服务器写入请求的时间。
Message Processor I/O 超时默认值为 55 seconds
。此超时期限适用于在目标端点配置和 API 代理的 ServiceCallout 政策中配置的后端服务器。
您可以根据自己的需求在 55 seconds
的默认值的基础上增加或减少消息处理器的 I/O 超时。您可以在以下位置对其进行配置:
- 在 API 代理中
- 目标端点
- ServiceCallout 政策
- 在消息处理器上
以下属性用于控制消息处理器上的 I/O 超时:
物业名称 | 位置 | 说明 |
---|---|---|
io.timeout.millis
|
API 代理:
|
这是消息处理器执行以下操作的最长时间:
如果后端服务器在此超时期限内没有响应,消息处理器就会超时。
默认情况下,此属性采用为消息处理器上的 如果为特定 API 代理使用新的超时值修改了此属性,则只有该 API 代理会受到影响。 |
HTTPTransport.io.timeout.millis
|
消息处理器 |
这是消息处理器执行以下操作的最长时间:
如果后端服务器在此超时期限内没有响应,消息处理器就会超时。 此属性用于此消息处理器上运行的所有 API 代理。
此属性的默认值为
您可以按照在消息处理器上配置 I/O 超时中的说明修改此属性,也可以通过在 API 代理级别设置 |
准备工作
在使用本文档中的步骤之前,请务必了解以下主题:
- 如果您不熟悉 I/O 超时,请参阅
TargetEndpoint 传输属性规范中的
io.timeout.millis
属性说明。 - 如果您不熟悉如何为 Private Cloud 配置 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 超时。I/O 超时可通过 <Timeout>
元素或 io.timeout.millis
属性进行配置。<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 超时。
您可以根据如何配置 Edge 中所述的语法使用令牌,通过属性 HTTPTransport.io.timeout.millis
来配置 I/O 超时值,该属性表示消息处理器组件上的 I/O 超时值(以毫秒为单位)。
如需在消息处理器上配置 I/O 超时,请执行以下操作:
- 在 Message Processor 计算机上,在编辑器中打开以下文件。如果不存在,则创建它。
/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
是否已使用新值设置。
- 在 Message Processor 机器上,在
/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 秒。
下一步该做什么?
了解如何 在路由器上配置 I/O 超时