如何基于 XML 配置文件在 WSO2 ESB 中动态路由消息 [英] How to dynamically route message in WSO2 ESB based on XML configuration file

查看:14
本文介绍了如何基于 XML 配置文件在 WSO2 ESB 中动态路由消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据存储为本地条目 (key=mapping_id_ep_v1.xml) 的 XML 片段中的信息来路由消息.用于查找正确端点的 id,它是消息正文的一部分.

I am trying to route a message based on information in a XML snippet stored as a local entry (key=mapping_id_ep_v1.xml). The id used to look-up the correct endpoint and it is part of the message body.

这是用于将 id 映射到端点的 XML 片段:

This is the XML snippet used to map id's to endpoints:

<mappings>
    <mapping id="ep_1">http://localhost:8280/services/ep_1</mapping>
    <mapping id="ep_2">http://localhost:8280/services/ep_2</mapping>
    <mapping id="ep_3">http://localhost:8280/services/ep_3</mapping>
<mappings>

我使用以下语句从正文中检索 id 以查找端点:

I retrieve the id from the body to look-up the endpoint using the following statement:

<property name="LOOK-UP" expression="//controleFile/id" />

我可以按顺序使用以下条目将 XML 文件加载到属性文件中:

I can load the XML file into a property file using the following entry in a sequence:

<property name="MAPPING" expression="get-property('mapping_id_ep_v1.xml')" />

我使用以下语句记录属性:

I log the property using the following statement:

<log level="custom">
    <property name="Look-up" expression="get-property('LOOK-UP')" />
    <property name="Mapping" expression="get-property('MAPPING')" />
</log>

到目前为止一切顺利.我无法弄清楚如何从 MAPPING 属性中检索正确的端点.有人可以帮忙吗?

So far so good. I haven't been able to figure out how to retrieve the correct endpoint from the MAPPING property. Can anyone help out?

推荐答案

我用不同的方法解决了我的问题.它与给定 bij fipris 的答案一致.

I solved my question using a different approach. It is in line with the answer given bij fipries.

在代理中我添加了以下内容:

In the proxy I added the following:

 <property name="MAPPING" expression="get-property('mapping_id_ep_v1')" />
 <property name="LOOK_UP" expression="//controlFile/id" />
 <log level="custom">
    <property name="MAPPING" expression="get-property('MAPPING')" />
    <property name="LOOK_UP" expression="get-property('LOOK_UP')" />
 </log>
 <script language="js" key="testScript_2" function="getEndpointByID" />
 <log level="custom">
    <property name="EP" expression="get-property('EP')" />
 </log>

这是mapping_id_ep_v1的内容:

This is the contents of mapping_id_ep_v1:

<mappings>
    <mapping id="ep_1">http://localhost:8280/services/ep_1</mapping>
    <mapping id="ep_2">http://localhost:8280/services/ep_2</mapping>
    <mapping id="ep_3">http://localhost:8280/services/ep_3</mapping>
<mappings>

这是 TestScript_2 中的代码:

This is the code in TestScript_2:

<x>

  function getEndpointByID(mc) {
     var xml = new XML(mc.getProperty('MAPPING'));
     var look_up = new XML(mc.getProperty('LOOK_UP'));
     var ep = xml..mapping.(@id == look_up);
     mc.setProperty('EP', ep + '');
  }

</x>

代理将映射 xml 加载到属性中.此属性在 javascript 代码中转换为 XML,然后使用 LOOK_UP 检索正确的端点.

The proxy loads the mapping xml into a property. This property is converted to XML in the javascript code and then using LOOK_UP the correct endpoint is retrieved.

希望这对其他人有所帮助.

Hope this helps someone else.

问候,尼德基尔

这篇关于如何基于 XML 配置文件在 WSO2 ESB 中动态路由消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆