简体   繁体   English

在Apigee中,如何为统计信息收集器策略要使用的Javascript中的变量分配值?

[英]In Apigee, how to assign a value to a variable in Javascript to be used by the Statistics Collector policy?

While working with an Apigee API proxy, I have obtained the value of a query parameter from the URL and extracted a part of it. 使用Apigee API代理时,我已从URL获取查询参数的值并提取了一部分。 I need to get a message count on the extracted part of the query parameter using the Statistics Collector Policy. 我需要使用统计信息收集器策略获取查询参数提取部分的消息计数。

An example: orgname-test.apigee.net/v0/myURL?Qparam=abc.9421.345.ghi567 is the URL with the query parameter 'Qparam' with a value of 'abc.9421.345.ghi567'. 例如:orgname-test.apigee.net/v0/myURL?Qparam=abc.9421.345.ghi567是查询参数为'Qparam'且值为'abc.9421.345.ghi567'的URL。

Using the Javascript policy, I managed to obtain the query parameter value and extract the part coming after the third dot, that is; 使用Javascript策略,我设法获得了查询参数值并提取了第三个点之后的部分,即: '345'. '345'。 I need to use the Statistics Collector policy on this part of the query parameter value ('345') to get a count of how many times it was called. 我需要在查询参数值(“ 345”)的这一部分上使用统计信息收集器策略,以获取对其调用次数的计数。 How can I do that? 我怎样才能做到这一点? And is this the right approach overall? 这是正确的方法吗?

1) After query parameter is parsed and the value is retrieved from the string, set a flow variable in the JavaScript policy such as: 1)解析查询参数并从字符串中检索值后,请在JavaScript策略中设置流变量,例如:

context.setVariable('QParam.thirdElement', value) context.setVariable('QParam.thirdElement',值)

2) Set QParam.thirdElement in Statistic Collector policy: 2)在统计收集器策略中设置QParam.thirdElement:

This value will then be available later on to be set as a reference in the statistics collector policy. 然后,此值将在以后可用,以在统计信息收集器策略中设置为参考。 And could be used as: 可以用作:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="statisticscollector-analyze-QParam">
    <DisplayName>StatisticsCollector-AnalyzeQParam</DisplayName>
    <FaultRules/>
    <Properties/>
    <Statistics>
        <Statistic name="thirdElement" ref="QParam.thirdElement" type="STRING">id</Statistic>
    </Statistics>
</StatisticsCollector>

Your approach should be fine, if there's no other way to get this value in a separate parameter. 如果没有其他方法可以在单独的参数中获取此值,则您的方法应该很好。 Perhaps using RegEx to extract the value from QParam. 也许使用RegEx从QParam中提取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM