WSO2 ESB在序列中获取租户名称属性

问题描述 投票:1回答:1

我正在使用WSO2 ESB处理消息,然后将其发送到外部消息代理。我想根据租户名称命名目标队列。但是,我怎样才能获得租户名称?

wso2 wso2esb
1个回答
3
投票

实际上,您无法直接获取租户名称,因为根据代码,我们不会将租户域作为消息上下文中的单个属性传递。但您可以在包含axis2消息上下文的“TransportInURL”属性中找到此租户名称。 “TransportInURL”属性值的形成如下。

  • TransportInURL:/ t / tenant_domain或tenant_name / api上下文部分
  • 例如:/t/wso2.com/abc/v1

然后,为了满足您的要求,您可以使用子字符串函数和属性介体来隔离租户名称,如下所示。

<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>                        
© www.soinside.com 2019 - 2024. All rights reserved.