Spring Cloud Stream + Google Pub/Sup:功能绑定不起作用

Spring Cloud Stream + Google Pub/Sup: functional binding not woring

我正在尝试在同一应用程序中使用来自不同 PubSub 主题的多条消息。其中一个被轮询,其他应该是功能绑定。我的功能性消费者不工作。

@Bean
public Consumer<MessageA> messageAMessageHandler() {
    return message -> { ... }
}

@Scheduled(initialDelay = 60 * 1000, fixedRate = 600 * 1000)
public void pollBMessages() {
    this.bMessageSource.b().poll(m -> { ... }, new ParameterizedTypeReference<MessageB>() {
    });
}

我的application.yml:

spring:
  cloud:

    stream:
      pubsub:
        default:
          consumer:
            auto-create-resources: true

      gcp:
        pubsub:
          bindings:
            message-a-input:
              consumer:
                ack-mode: manual

      bindings:
        messageAMessageHandler-in-0:
          destination: message-b-topic
          group: my-service
        message-a-input:
          destination: message-a-topic
          group: my-service

    function:
      definition: messageAMessageHandler;messageCMessageHandler

轮询基于注释的 MessageSource 效果很好,但未获取功能绑定。它们在我的应用程序上下文中是 Bean,但云流或 gcp pubsub 会忽略它们。没有创建订阅,也没有消费消息。

我错过了什么?

由于您的轮询活页夹正在运行,您的代码中可能有 @EnabledBinding 注释。如果查看应用程序输出,您会看到如下消息:

onConfiguration$FunctionBindingRegistrar : Functional binding is disabled due to the presense of @EnableBinding annotation in your configuration.

Spring Cloud Stream 不支持混合使用传统(基于注释)和函数式绑定样式。