You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Service Bus多主题多订阅同时消费配置问题求助

解决Azure Service Bus多主题订阅消费时'fullyQualifiedNamespace'为null的问题

同一项目里有两个Azure Service Bus主题,每个主题下各2个订阅,需要同时消费这4个订阅。单独消费单个主题的两个订阅时一切正常,但同时配置两个主题的消费逻辑后,出现错误:'fullyQualifiedNamespace' can't be null。即使配置了正确的命名空间,该值仍会被覆盖为null。

你给出的原配置如下:

cloud:
  azure:
    servicebus:
      topic1:
        bindings:
          consumeSuscripcionUno-in-0:
            group: topic1
          consumeSuscripcionDos-in-0:
            group: topic1
        connection-string: "connection-string"
        enabled: true
      topic2:
        bindings:
          consumeSuscripcionUno-in-0:
            group: topic2
        connection-string: "connection-string"
        enabled: true

问题原因

你的配置结构不符合Spring Cloud Azure Service Bus的多主题配置规范,connection-string的层级错误,且bindings的用法不适用于多主题订阅场景,导致框架无法正确解析命名空间信息,最终抛出fullyQualifiedNamespace为null的错误。

修正后的配置方案

根据你的场景,分两种情况给出配置:

情况1:两个主题属于同一个Service Bus命名空间

直接在根节点配置共享的连接字符串,再分别定义每个主题的订阅:

cloud:
  azure:
    servicebus:
      connection-string: "你的实际连接字符串"
      topics:
        topic1:
          subscriptions:
            consumeSuscripcionUno:
              enabled: true
            consumeSuscripcionDos:
              enabled: true
        topic2:
          subscriptions:
            consumeSuscripcionUno:
              enabled: true
            consumeSuscripcionDos:
              enabled: true

情况2:两个主题属于不同的Service Bus命名空间

使用namespaces节点分别配置每个命名空间的连接信息和对应的主题订阅:

cloud:
  azure:
    servicebus:
      namespaces:
        namespace-topic1:
          connection-string: "topic1所属命名空间的连接字符串"
          topics:
            topic1:
              subscriptions:
                consumeSuscripcionUno:
                  enabled: true
                consumeSuscripcionDos:
                  enabled: true
        namespace-topic2:
          connection-string: "topic2所属命名空间的连接字符串"
          topics:
            topic2:
              subscriptions:
                consumeSuscripcionUno:
                  enabled: true
                consumeSuscripcionDos:
                  enabled: true

注意事项

  • 替换配置中的"你的实际连接字符串"为真实的Azure Service Bus连接字符串
  • 确保每个订阅的名称和你代码中定义的消费者绑定名称一致
  • 若使用Spring Cloud Stream的绑定方式,需确保spring.cloud.stream.bindings下的配置和上述Service Bus配置对应匹配

内容的提问来源于stack exchange,提问作者cristian2342341

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 04:05:12