如何在WSO2 Integration Studio中配置HTTP端点地址为环境变量?
在WSO2 Integration Studio中为HTTP端点配置外部环境变量的具体方法
方式一:使用系统环境变量
- 先在系统中定义环境变量:
- 开发环境:设置
TEST_ENDPOINT_HOST=localhost:XXX - 生产环境:设置为对应生产地址,比如
TEST_ENDPOINT_HOST=prod.example.com:YYYY
- 开发环境:设置
- 修改HTTP端点的
uri-template,用${env:变量名}引用:
<call> <endpoint> <http method="get" uri-template="http://${env:TEST_ENDPOINT_HOST}/test"> <suspendOnFailure> <initialDuration>-1</initialDuration> <progressionFactor>-1</progressionFactor> <maximumDuration>0</maximumDuration> </suspendOnFailure> <markForSuspension> <retriesBeforeSuspension>0</retriesBeforeSuspension> </markForSuspension> </http> </endpoint> </call>
- 注意:启动WSO2服务器前,要确保进程能读取到这个环境变量。如果是在脚本中启动,可在启动前添加
export TEST_ENDPOINT_HOST=xxx。
方式二:使用WSO2配置文件(deployment.toml)
- 在WSO2的
repository/conf/deployment.toml中添加自定义配置:
[custom] test_endpoint_host = "localhost:XXX"
- 生产环境替换这个文件为对应内容即可,比如
test_endpoint_host = "prod.example.com:YYYY" - 修改HTTP端点的
uri-template,用${sys:custom.变量名}引用:
<call> <endpoint> <http method="get" uri-template="http://${sys:custom.test_endpoint_host}/test"> <suspendOnFailure> <initialDuration>-1</initialDuration> <progressionFactor>-1</progressionFactor> <maximumDuration>0</maximumDuration> </suspendOnFailure> <markForSuspension> <retriesBeforeSuspension>0</retriesBeforeSuspension> </markForSuspension> </http> </endpoint> </call>
验证配置
修改变量值后,重启WSO2服务器,调用服务检查是否正确访问目标端点。
内容的提问来源于stack exchange,提问作者Ahmet Kalem
相关产品推荐
相关产品推荐

