属性字符串值匹配
您可以使用字符串值来匹配消息属性和筛选消息。在 JSON 策略中,用双引号将字符串值引起来。
您可以使用以下字符串操作来匹配消息属性。
精确匹配
在策略属性值与一个或多个消息属性值匹配时,会进行精确匹配。
考虑以下策略属性:
"customer_interests": ["rugby", "tennis"]
它匹配以下消息属性:
"customer_interests": {"Type": "String", "Value": "rugby"}
"customer_interests": {"Type": "String", "Value": "tennis"}
但是,它不匹配以下消息属性:
"customer_interests": {"Type": "String", "Value": "baseball"}
前缀匹配
当策略属性值包含关键字 prefix
时,它匹配以指定字符开头的任何消息属性值。
考虑以下策略属性:
"customer_interests": [{"prefix": "bas"}]
它匹配以下任一消息属性:
"customer_interests": {"Type": "String", "Value": "baseball"}
"customer_interests": {"Type": "String", "Value": "basketball"}
但是,它不匹配以下消息属性:
"customer_interests": {"Type": "String", "Value": "rugby"}
Anything-but 匹配
当策略属性值包含关键字 anything-but
时,它匹配不 包含任一策略属性值的任何消息属性。
考虑以下策略属性:
"customer_interests": [{"anything-but": ["rugby", "tennis"]}]
它匹配以下任一消息属性:
"customer_interests": {"Type": "String", "Value": "baseball"}
"customer_interests": {"Type": "String", "Value": "football"}
它还匹配以下消息属性(因为它包含的值不是 rugby
或 tennis
):
"customer_interests": {"Type": "String.Array", "Value": "[\"rugby\", \"baseball\"]"}
但是,它不匹配以下消息属性:
"customer_interests": {"Type": "String", "Value": "rugby"}
将前缀与 anything-but
运算符结合使用
要进行属性字符串匹配,您也可以将前缀与 anything-but
运算符结合使用。
例如,以下策略属性拒绝 order-
前缀:
"event":[{"anything-but": {"prefix": "order-"}}]
它匹配以下任一属性:
"event": {"Type": "String", "Value": "data-entry"}
"event": {"Type": "String", "Value": "order_number"}
但是,它不匹配以下属性:
"event": {"Type": "String", "Value": "order-cancelled"}
IP 地址匹配
您可以使用 cidr
运算符来检查传入消息是否源自特定 IP 地址或子网。
考虑以下策略属性:
"source_ip":[{"cidr": "10.0.0.0/24"}]
它匹配以下任一消息属性:
"source_ip": {"Type": "String", "Value": "10.0.0.0"}
"source_ip": {"Type": "String", "Value": "10.0.0.255"}
但是,它不匹配以下消息属性:
"source_ip": {"Type": "String", "Value": "10.1.1.0"}