跳到主要内容

主题订阅中的通配符字符

在SMF(Solace消息格式)主题订阅中使用*>字符时,它们作为通配符,影响可能出现的主题匹配。

*>字符在发布主题中使用时,它们没有任何特殊含义。它们被视为字面字符,而不是通配符,不影响主题匹配。然而,为了避免混淆,Solace不推荐在发布主题中使用*>作为字面字符。

使用*通配符

*通配符的功能如下:

  1. *单独出现在主题订阅的一个级别中(例如animals/*/catsanimals/domestic/*)时,表示在该级别进行通配符匹配。

    主题订阅末尾的*通配符仅在该级别进行通配符匹配。

    示例:animals/domestic/*匹配主题animals/domestic/catsanimals/domestic/dogs,但不匹配主题animals/domestic/dogs/beagles

  2. *在主题订阅的一个级别中跟在主题前缀后面时(例如animals/red*/wild),表示在该级别进行“前缀和0个或多个”匹配。

    示例:animals/red*/wild匹配主题animals/red/wildanimals/reddish/wild

  3. *可以在主题订阅的多个级别中使用,无论是否有主题前缀。

    示例:animals/*/cats/*有效,匹配主题animals/domestic/cats/persiananimals/wild/cats/leopard,但不匹配主题animals/domestic/cats/persian/grey,也不匹配主题animals/domestic/dogs/beagles

  4. 在级别中的任意位置使用*,且不受前面规则涵盖的,被视为字面字符;不支持一般子字符串匹配。

    示例:主题订阅animals/*broanimals/br*wn中的*被视为字面*,不是通配符。

使用>通配符

>通配符的功能如下:

  1. >单独出现在主题订阅的最后一个级别中(例如animals/domestic/>)时,为与订阅具有相同前缀的任何主题提供“一个或多个”通配符匹配。

    示例:animals/domestic/>不匹配主题animals/domestic,但它匹配主题animals/domestic/catsanimals/domestic/dogsanimals/domestic/dogs/beaglesanimals/domestic/dogs/beagles/long-eared

  2. 除了单独出现在主题订阅字符串最后一个级别之外,>在任何地方出现的都被视为>字符,而不是通配符。

    示例:animals>animals/domestic>是字面订阅,不匹配animals/domestic/dogs/beagles

  3. >*字符可以在同一主题订阅中一起使用。

    示例:animals/*/cats/>匹配主题animals/domestic/cats/persiananimals/wild/cats/leopardanimals/domestic/cats/persian/grey,但不匹配主题animals/domestic/dogs/beagles

通配符限制

通配符有以下限制:

  • 事件代理为每个客户端自动创建以#P2P为前缀的主题订阅,这允许消息直接发送到该客户端(例如,在请求/回复场景中)。因此,为确保通配符不能用于接收其他客户端收件箱中的消息,*>通配符永远不会匹配字符串#P2P,无论通配符或#P2P字符串在主题订阅字符串中的位置如何。

  • 发布到以$字符开头的主题的消息永远不会被主题订阅的第一个级别中的独立通配符(*/..>)匹配。这确保了以$字符开头的系统和事件日志消息不会被意外包含在主题订阅中。

通配符示例

下表提供了使用通配符时主题订阅匹配的示例。

通配符主题匹配主题如下:不匹配主题如下:
animals/domestic/*animals/domestic/cats
animals/domestic/dogsanimals/domestic/dogs/beagles
animals/*/cats/*animals/domestic/cats/persian
animals/wild/cats/leopardanimals/domestic/cats/persian/grey
animals/domestic/dogs/beagles
animals/domestic/dog*animals/domestic/dog
animals/domestic/doggyanimals/domestic/dog/beagle
animals/domestic/cat
animals/domestic/>animals/domestic/cats
animals/domestic/dogs/beaglesanimals
animals/domestic
animals/Domestic
animals/*/cats/>animals/domestic/cats/tabby/grey
animals/wild/cats/leopardanimals/domestic/dogs/beagles
my/test/*my/test/topicMy/Test/Topic
my/test