Spring Cloud GCP provides a Spring Cloud Stream binder to Google Cloud Pub/Sub.
The provided binder relies on the Spring Integration Channel Adapters for Google Cloud Pub/Sub.
Maven coordinates, using Spring Cloud GCP BOM:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gcp-pubsub-stream-binder</artifactId> </dependency>
Gradle coordinates:
dependencies { compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-pubsub-stream-binder' }
A sample application is available.
This binder binds producers to Google Cloud Pub/Sub topics and consumers to subscriptions.
![]() | Note |
---|---|
Partitioning and consumer groups are not currently supported by this binder. |
You can configure the Spring Cloud Stream Binder for Google Cloud Pub/Sub to automatically generate the underlying resources, like the Google Cloud Pub/Sub subscriptions for the consumers.
For that, you can use the spring.cloud.stream.gcp.pubsub.bindings.[CHANNEL-NAME].consumer.auto-create-resources
property, which is turned ON by default.
If automatic resource creation is turned ON and the subscription and the topic do not exist for a consumer, a subscription and a topic will be created with the same name.
For example, for the following configuration, a topic and a subscription called myConsumer
would be created.
application.properties.
spring.cloud.stream.bindings.output.destination=myConsumer spring.cloud.stream.gcp.pubsub.bindings.output.consumer.auto-create-resources=true
If you are using Pub/Sub auto-configuration from the Spring Cloud GCP Pub/Sub Starter, you should refer to the configuration section for other Pub/Sub parameters.
![]() | Note |
---|---|
To use this binder with a running emulator, configure its host and port via
|