如何在消息处理器的 WSO2 Enterprise Integrator 中使用我的注册表配置

How to use my registry configurations in WSO2 Enterprise Integrator in a Message Processor

我正在使用 WSO2 Enterprise Integrator 6.6.0。我的应用程序中有一个文件 usage-service-config,该文件位于下方

<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="usage-service-config" xmlns="http://ws.apache.org/ns/synapse">
    <configuration xmlns="http://config.usageService.gravity.hp.com">
        <!-- Local End Points -->
        <dss_ep>https://localhost:8243/services/ds</dss_ep>
        <api>https://localhost:8243/usage</api>
        <api_ep>https://localhost:8243/api</api_ep>
    </configuration>
</localEntry>

我想在通过 Message Processor

调用端点时在端点中使用上述文件中存储的值之一

我怎样才能做到这一点?

这是我的应用程序的流程:

序列:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="usageService-get-processDcsCustomers-seq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <property description="Get Configuration" expression="get-property('registry','conf:/usage-service/usage-service-config.xml')" name="usage-service-config" scope="default" type="OM"/>
    <property description="Get DSS Endpoint" expression="$ctx:usage-service-config//n0:usageService_dss_ep/text()" name="uri.var.usageService_dss_ep" scope="default" type="STRING" xmlns:n0="http://config.usageService.gravity.hp.com"/>
    <call>
        <endpoint key="some-data-ep"/>
    </call>
    <log level="full"/>
    <foreach expression="//gravity:allCustomers/gravity:customers" id="allCustomers" xmlns:gravity="some-ds">
        <sequence>
            <property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
            <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
            <store messageStore="my-ms"/>
        </sequence>
    </foreach>
</sequence>

消息存储:

<?xml version="1.0" encoding="UTF-8"?>
<messageStore class="org.apache.synapse.message.store.impl.memory.InMemoryStore" name="my-ms" xmlns="http://ws.apache.org/ns/synapse"/>

消息处理器:

<?xml version="1.0" encoding="UTF-8"?>
<messageProcessor class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor" messageStore="my-ms" name="my-mp" targetEndpoint="my-ep" xmlns="http://ws.apache.org/ns/synapse">
    <parameter name="client.retry.interval">1000</parameter>
    <parameter name="max.delivery.attempts">1</parameter>
    <parameter name="member.count">1</parameter>
    <parameter name="non.retry.status.codes">400</parameter>
    <parameter name="max.delivery.drop">Enabled</parameter>
    <parameter name="interval">1000</parameter>
    <parameter name="is.active">true</parameter>
    <parameter name="target.endpoint">my-ep</parameter>
</messageProcessor>

端点:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="my-ep" xmlns="http://ws.apache.org/ns/synapse">
    <http method="post" uri-template="https://localhost:8243/api/abc"/>
</endpoint>

API:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/api" name="my-api" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="pOST" protocol="https" uri-template="/health">
        <inSequence>
            <property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
            <sequence key="my-seq"/>
            <loopback/>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
        <faultSequence/>
    </resource>
</api>

如何使用配置文件的值来调用端点?

I want to use one of the values stored in the above file in an endpoint while calling the endpoint through a Message Processor

消息处理器本身可能只配置了一个静态值。您仍然可以创建代理服务或 api,您可以在其中从注册表中读取值并调用配置的端点。

如果要动态更改目标端点,可以更改To header。

<property name="xmlvalue" expression="get-property('registry', 'gov:/xml/body.xml')" type="OM" /
<header name="To" expression="$ctx:xmlvalue//api_ep" />
<!-- send or call ->

I was able to do overcome this by getting my registry configurations in the sequence where I'm storing the data in Message Store. and then used the same property in the Endpoint that I was calling from Message Store

序列

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="usageService-get-processDcsCustomers-seq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <property description="Get Configuration" expression="get-property('registry','conf:/usage-service/usage-service-config.xml')" name="usage-service-config" scope="default" type="OM"/>
    <property description="Get DSS Endpoint" expression="$ctx:usage-service-config//n0:usageService_dss_ep/text()" name="uri.var.usageService_dss_ep" scope="default" type="STRING" xmlns:n0="http://config.usageService.gravity.hp.com"/>
    <property description="Get API Endpiont" expression="$ctx:usage-service-config//n0:api_ep/text()" name="uri.var.link" scope="default" type="STRING" xmlns:n0="http://config.usageService.gravity.hp.com"/>
    <call>
        <endpoint key="some-data-ep"/>
    </call>
    <log level="full"/>
    <foreach expression="//gravity:allCustomers/gravity:customers" id="allCustomers" xmlns:gravity="some-ds">
        <sequence>
            <property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
            <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
            <store messageStore="my-ms"/>
        </sequence>
    </foreach>
</sequence>

端点

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="my-ep" xmlns="http://ws.apache.org/ns/synapse">
    <http method="post" uri-template="{uri.var.link}/abc"/>
</endpoint>