Mule 如何使用';选择路由器&x27;在Anypoint studio中执行此场景?

Mule 如何使用';选择路由器&x27;在Anypoint studio中执行此场景?,mule,anypoint-studio,dataweave,mulesoft,Mule,Anypoint Studio,Dataweave,Mulesoft,我使用RAML文件通过APIKit路由器生成流。我有example.json作为示例响应。 我的RAML代码是: #%RAML 0.8 --- title: TestEmployee API version: v1 /employee: get: queryParameters: id: enum: [1,2,3,4] required: true type: string description: Employee id name:

我使用RAML文件通过APIKit路由器生成流。我有example.json作为示例响应。 我的RAML代码是:

 #%RAML 0.8
 ---
 title: TestEmployee API
 version: v1

 /employee:
  get:
 queryParameters:
  id:
    enum: [1,2,3,4]
    required: true
    type: string
    description: Employee id
   name:
    enum: [Charles,John,Neha,Shruti]
    required: true
    type: string
    description: Employee_name
   responses:
   200:
    body:
      application/json:
        example: !include example.json
JSON示例响应为:

 [
 {
 "id": 1,
 "name":"Charles",
 "code": "C1ENU00",
 "dateofjoining":"2019/06/24",
 "domain":"ENU",
 "address":"Hyderabad",
 "phone": 9865458936,
 "program": "WASE"
 },
 {
 "id": 2,
 "name":"John",
 "code": "C2DIG00",
 "dateofjoining":"2019/06/24",
 "domain":"DIGITAL",
 "address":"Chennai",
 "phone": 9756359864,
 "program": "ELITE"
 }
我想使用choice路由器在“id”和“name”匹配时适当地调用流。与查询参数类似,如果用户输入'id=1&name=Charles',则只有choice router会调用main flow,否则它应该调用默认流。最初,有效负载设置为“示例JSON响应”主体。请引导我实现这一目标


以下是供参考的流程

将choice router中的
when
expression
属性设置为与用例匹配的Dataweave表达式。您可以使用attributes.queryParams.YOUR-QUERY-PARAM-name语法按名称访问queryParams:

#[attributes.queryParams.id=='1' and attributes.queryParams.name=='Charles']
然后为您需要的每个路由添加一个when作用域,并为默认路由添加一个可选的other:

<choice>
    <when
        expression="#[attributes.queryParams.id=='1' and attributes.queryParams.name=='Charles']">
        <flow-ref name="some-flow" />
    </when>
    <otherwise>
        <flow-ref name="some-other-flow" />
    </otherwise>
</choice>

将choice router中的when
expression
属性设置为与用例匹配的Dataweave表达式。您可以使用attributes.queryParams.YOUR-QUERY-PARAM-name语法按名称访问queryParams:

#[attributes.queryParams.id=='1' and attributes.queryParams.name=='Charles']
然后为您需要的每个路由添加一个when作用域,并为默认路由添加一个可选的other:

<choice>
    <when
        expression="#[attributes.queryParams.id=='1' and attributes.queryParams.name=='Charles']">
        <flow-ref name="some-flow" />
    </when>
    <otherwise>
        <flow-ref name="some-other-flow" />
    </otherwise>
</choice>

您可以简单地在set变量中定义id和name,将查询参数与set变量进行比较
=
您可以简单地在set变量中定义id和name,将查询参数与set变量进行比较
=