1

I'm trying to consume multiple Messages from different PubSub Topics in the same Application. One of them is polled the others should be functional bindings. My functional consumers dont work.

@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>() {
    });
}

My 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

Polling the annotation based MessageSource works well, but the functional bindings are not picked up. They are Beans in my application context, but cloud stream or gcp pubsub ignores them. no subscriptions are created and no messages consumed.

What am I missing?

Laures
  • 5,389
  • 11
  • 50
  • 76

1 Answers1

3

Since your polled binder is working, you probably have the @EnabledBinding annotation somewhere in your code. If you look at the application output, you'll see a message like this:

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

Spring Cloud Stream does not support mixing legacy (annotation-based) and functional binding styles.

Elena Felder
  • 456
  • 3
  • 8
  • thank you. I did not see that log message because of misconfigured log-levels. Am i correct to assume that, because there is no functional way to poll messages, i have to change my consumers to the legacy/annotation approach? – Laures May 06 '20 at 19:27
  • Well, you could turn it upside down and make your consumers be *producers* instead -- autowire `PubSubTemplate` (which is a low-level, non-SCS-specific object for interacting with Cloud Pub/Sub) and use one of its `pull()` method directly. But it's an interesting question to ask on the Spring Cloud Stream gitter or issue tracker -- whether polling consumers have any role in the new functional model. – Elena Felder May 06 '20 at 20:43