GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
423 stars 315 forks source link

PubSub Stream Binder: Binding multiple subscriptions to same method #2260

Closed SheheryarAamir closed 1 year ago

SheheryarAamir commented 1 year ago

Describe the bug Let say I was three PROJECTS project_A, project_B and project_C. Project A and B have a topic topic_A and topic_B. In project_C I have two subscriptions subscription_A (subscribe to topic_A) and subscription_B (subscribe to topic_B).

I want to bind both subscription to same function functionToReceiveMessageFromSubscriptionAandB

So far, I am unable to find how to set this up with google pubsub stream binder. Could someone guide if this can be done ?

Sample

spring:
  cloud:
     stream:
        gcp:
          pubsub:
             default:
               consumer:
                 subscriptionName: subscription_A, subscription_B
      bindings:
        functionToReceiveMessageFromSubscriptionAandB-in-0
           destination: 

Spring Cloud GCP PubSub Stream binder version: 4.8.2

meltsufin commented 1 year ago

I don't think it's possible with Spring Cloud Stream, having nothing to do with Pub/Sub. Can you just bind to two different methods where they in turn call a single method?

SheheryarAamir commented 1 year ago

@meltsufin how to adding multiple subscription, because above provided yaml doesnt allow

for example I cant do this

spring:
  cloud:
     stream:
        gcp:
          pubsub:
             default:
               consumer01:
                 subscriptionName: subscription_A
               consumer02:
                 subscriptionName: subscription_A
      bindings:
        functionToReceiveMessageFromSubscriptionA-in-0
           destination: topic_A
        functionToReceiveMessageFromSubscriptionA-in-0
           destination: topic_B
meltsufin commented 1 year ago

@SheheryarAamir You shouldn't use default in this case. Try: spring.cloud.stream.gcp.pubsub.bindings.functionToReceiveMessageFromSubscriptionA-in-0.consumer.subscriptionName. See: https://googlecloudplatform.github.io/spring-cloud-gcp/reference/html/index.html#consumer-destination-configuration.

SheheryarAamir commented 1 year ago

Thank you @meltsufin