GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp
Enable virtual threads support for PubSub consumers
- Dominant language
- Java
- Stars
- 551
- Forks
- 349
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
I've been experimenting with virtual threads on our Spring Boot application by using the property `spring.threads.virtual.enabled=true`.
Our application has a PubSub consumer that uses `spring-cloud-gcp-pubsub-stream-binder`, and I've noticed that it ignores the `spring.threads.virtual.enabled` property and keeps using platform threads to receive incoming messages.
Looking at the configuration it seems that the thread pools for consumers are created in the private method [GcpPubSubAutoConfiguration.registerSubscriberThreadPoolSchedulerBeans](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubAutoConfiguration.java#L466) and there's no way to customize the ThreadPool.
Spring's `ThreadPoolTaskScheduler` supports using virtual threads by calling its method `setVirtualThreads(true)`.
The ideal solution would be to enable virtual threads support automatically when `spring.threads.virtual.enabled` is set to `true`. Alternatively, making consumer thread pools customizable by the user would also be an acceptable solution.
Contributor guide
Research direction
Start in spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/pubsub/GcpPubSubAutoConfiguration.java, at registerSubscriberThreadPoolSchedulerBeans. Review how the consumer thread pools are created and how ThreadPoolTaskScheduler supports virtual threads, then trace the spring.threads.virtual.enabled property. Done means PubSub consumers honor that property or expose a supported way to customize their thread pools.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- google-cloud, java, spring-boot
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100