WSO2 ESB 获取序列中的租户名称属性
WSO2 ESB get the tenant name property in the sequence
我正在使用 WSO2 ESB 处理消息,然后再将其发送到外部消息代理。
我想根据租户名称命名目标队列。但是,如何获取租户名称?
实际上,您无法直接获取租户名称,因为根据代码,我们不会在消息上下文中将租户域作为个体 属性 传递。但是您可以在包含 axis2 消息上下文的 "TransportInURL" 属性 中找到此租户名称。 "TransportInURL" 属性 值形成如下。
- TransportInURL:/t/tenant_domain 或 tenant_name/api 上下文部分
- 例如:/t/wso2.com/abc/v1
那么为了达到你的要求,你可以使用带有属性中介的substring函数来隔离租户名称,如下所示。
<property name="tenant" expression="fn:substring-before(fn:substring-after($axis2:TransportInURL, '/t/'), '/')"/>
例如:
- 输入:/t/wso2.com/abc/v1
- 结果:wso2.com
示例API:您可以看到如何使用此属性获取租户名称。
<api xmlns="http://ws.apache.org/ns/synapse" name="ABC" context="/t/wso2.com/abc" version="v1" version-type="context">
<resource methods="GET">
<inSequence>
<property name="tenant" expression="fn:substring-before(fn:substring-after($axis2:TransportInURL, '/t/'), '/')"/>
<log level="full">
<property name="tenantValue" expression="get-property('tenant')"/>
</log>
<send>
<endpoint>
<http uri-template="http://www.mocky.io/v2/5c985f352f000064009f2f91"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>
我正在使用 WSO2 ESB 处理消息,然后再将其发送到外部消息代理。 我想根据租户名称命名目标队列。但是,如何获取租户名称?
实际上,您无法直接获取租户名称,因为根据代码,我们不会在消息上下文中将租户域作为个体 属性 传递。但是您可以在包含 axis2 消息上下文的 "TransportInURL" 属性 中找到此租户名称。 "TransportInURL" 属性 值形成如下。
- TransportInURL:/t/tenant_domain 或 tenant_name/api 上下文部分
- 例如:/t/wso2.com/abc/v1
那么为了达到你的要求,你可以使用带有属性中介的substring函数来隔离租户名称,如下所示。
<property name="tenant" expression="fn:substring-before(fn:substring-after($axis2:TransportInURL, '/t/'), '/')"/>
例如:
- 输入:/t/wso2.com/abc/v1
- 结果:wso2.com
示例API:您可以看到如何使用此属性获取租户名称。
<api xmlns="http://ws.apache.org/ns/synapse" name="ABC" context="/t/wso2.com/abc" version="v1" version-type="context">
<resource methods="GET">
<inSequence>
<property name="tenant" expression="fn:substring-before(fn:substring-after($axis2:TransportInURL, '/t/'), '/')"/>
<log level="full">
<property name="tenantValue" expression="get-property('tenant')"/>
</log>
<send>
<endpoint>
<http uri-template="http://www.mocky.io/v2/5c985f352f000064009f2f91"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>