RabbitMQ Topic 模式下 RoutingKey 通配符 # 和 * 的匹配规则详解
RabbitMQ 的 Topic 模式下,RoutingKey 可以使用通配符 '#' 和 '' 来匹配多个路由键。其中 '#' 代表任意字符串,而 '' 代表单个词。
例如,RoutingKey 'inform.#.email.#' 可以匹配 'inform.email'、'inform.email.send'、'inform.sms.email' 等路由键,因为 '#' 可以匹配任意字符串。而 'inform..sms' 只能匹配 'inform.sms'、'inform.sms.send' 等路由键,因为 '' 只能匹配单个词。
因此,只有 'inform.#.email.#' 可以匹配所有以 'inform' 开头,中间包含 'email' 的路由键,例如 'inform.email'、'inform.email.send'、'inform.sms.email' 等。
总结:
- '#' 代表任意字符串,可以匹配零个或多个词。
- '*' 代表单个词。
通过灵活运用通配符,我们可以更加便捷地实现消息的路由和匹配。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/oiae 著作权归作者所有。请勿转载和采集!