简体   繁体   English

如何在 APIGee 的分配消息策略中读取变量

[英]how to read variable in assign message policy in APIGee

In Apigee在 Apigee

given a variable in javascript policy, example: var value = 123;给定 javascript 策略中的一个变量,例如:var value = 123;

how to get this variable in the assign message policy?如何在分配消息策略中获取此变量?

by using {a} in the payload message is not reachable通过在负载消息中使用 {a} 无法访问

You have to set the variable in the context object using context.setVariable("variable-name", value);您必须使用context.setVariable("variable-name", value) 在上下文 object 中设置变量;

Refer to this variable in the assign_message policy using {variable-name}.使用 {variable-name} 在 assign_message 策略中引用此变量。

You can just set the context variable in jsPolicy like this:您可以像这样在 jsPolicy 中设置上下文变量:

context.setVariable("a","123");

You can use it after in any of the policies.您可以在任何政策之后使用它。

Ex:-前任:-

<QueryParams>
    <QueryParam name="a">{a}</QueryParam>
</QueryParams>

For the variable to be available for use in any Apigee policy, you first have to make it a flow variable.要使变量可用于任何 Apigee 政策,您首先必须将其设为流变量。 You can use Apigee's JavaScript Object Model method called context to to this (see ref here ).您可以使用 Apigee 的 JavaScript Object Model 方法调用context对此(参见此处参考)。 In your JS policy, you have var {some-value} = 123;在你的 JS 政策中,你有var {some-value} = 123; . . To make this available as a flow variable,introduce this line in your JS policy after the variable assignment: context.setVariable("preferred-variable-name", some-value);要使其可用作流变量,请在变量分配后在 JS 策略中引入此行: context.setVariable("preferred-variable-name", some-value);

You can now access this preferred-variable-name in your AM policy as show below:您现在可以在 AM 策略中访问此preferred-variable-name ,如下所示:

<AssignVariable>
    <Name>preferred-variable-name</Name>
    <Ref>preferred-variable-name</Ref>
</AssignVariable>

Just to mention it is possible to pass the value directly in the policy as well as shown below只是提一下,可以直接在策略中传递值,如下所示

<AssignVariable>
  <Name>variable_name</Name>
  <Value>123</Value>
</AssignVariable>

Read more here . 在这里阅读更多。

The <Name> tag can be set to any name. <Name>标签可以设置为任何名称。

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

相关问题 如何在 Apigee JavaScript 策略中提出 http 请求? - How to make http request in Apigee JavaScript policy? APIGEE:KeyValueMapOperations 策略中的 ExpiryTimeInSecs - APIGEE: ExpiryTimeInSecs in KeyValueMapOperations Policy Apigee:Javascript 标注策略返回错误响应。 我该如何解决这个错误? - Apigee : Javascript callout policy return error response. How can I resolve this error? 谷歌云平台——创建警报策略——如何在警报文档降价中指定消息变量? - google cloud platform -- creating alert policy -- how to specify message variable in alerting documentation markdown? 如何在 APIGEE 中为 HTTPTargetConnection 设置动态 LoadBalancer? - How to set dynamic LoadBalancer for HTTPTargetConnection in APIGEE? 使用 read function in Swift 将 firestore 值分配给变量 - Assign firestore value to variable using read function in Swift 如何创建匹配嵌套消息属性的 SNS 过滤策略? - How to create a SNS Filter Policy that matches nested message attributes? 如何在本地环境中向 apigee-emulator 添加扩展? - How to add extension to apigee-emulator on local environment? 如何在可观察的 Firebase 变量中分配 SnapshotChanges? - How Can I assign the SnapshotChanges in a Observable Firebase Variable? 将 ELB 帐户分配给 S3 存储桶策略 - Assign ELB Account to S3 Bucket Policy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM