Skip to content

Commit

Permalink
Fixes docs related to keeping a background user thread - pub/sub (#1404)
Browse files Browse the repository at this point in the history
* Fixes docs related to keeping a background user thread for command line pub/sub subscribers
  • Loading branch information
bijukunjummen committed Dec 29, 2022
1 parent e206907 commit 2802b8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
17 changes: 14 additions & 3 deletions docs/src/main/asciidoc/pubsub.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,20 @@ h|subscribeAndConvert(String subscription,
Class<T> payloadType) | same as `pull`, but converts message payload to `payloadType` using the converter configured in the template
|===

NOTE: As of version 1.2, subscribing by itself is not enough to keep an application running.
For a command-line application, you may want to provide your own `ThreadPoolTaskScheduler` bean named `pubsubSubscriberThreadPool`, which by default creates non-daemon threads that will keep an application from stopping.
This default behavior has been overridden in Spring Framework on Google Cloud for consistency with Cloud Pub/Sub client library, and to avoid holding up command-line applications that would like to shut down once their work is done.
[NOTE]
====
As of version 1.2, subscribing by itself is not enough to keep an application running.
For a command-line application, a way to keep the application running is to have a user thread(non-daemon thread) started up. A fake scheduled task creates a threadpool with non-daemon threads:
[source,java,indent=0]
----
@Scheduled (fixedRate = 1, timeUnit = TimeUnit.MINUTES)
public void fakeScheduledTask() {
// do nothing
}
----
Another option is to pull in `spring-boot-starter-web` or `spring-boot-starter-webflux` as a dependency which will start an embedded servlet container or reactive server keeping the application running in the background
====

==== Pulling messages from a subscription

Expand Down
17 changes: 9 additions & 8 deletions docs/src/main/md/pubsub.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,17 @@ Subscriber subscriber =
| **subscribeAndConvert(String subscription, Consumer\<ConvertedBasicAcknowledgeablePubsubMessage\<T\>\> messageConsumer, Class\<T\> payloadType)** | same as `pull`, but converts message payload to `payloadType` using the converter configured in the template |

<div class="note">
As of version 1.2, subscribing by itself is not enough to keep an application running.
For a command-line application, a way to keep the application running is to have a user thread(non-daemon thread) started up. A fake scheduled task creates a threadpool with non-daemon threads:

As of version 1.2, subscribing by itself is not enough to keep an
application running. For a command-line application, you may want to
provide your own `ThreadPoolTaskScheduler` bean named
`pubsubSubscriberThreadPool`, which by default creates non-daemon
threads that will keep an application from stopping. This default
behavior has been overridden in Spring Framework on Google Cloud for consistency with
Cloud Pub/Sub client library, and to avoid holding up command-line
applications that would like to shut down once their work is done.
```java
@Scheduled (fixedRate = 1, timeUnit = TimeUnit.MINUTES)
public void fakeScheduledTask() {
// do nothing
}
```

Another option is to pull in `spring-boot-starter-web` or `spring-boot-starter-webflux` as a dependency which will start an embedded servlet container or reactive server keeping the application running in the background
</div>

#### Pulling messages from a subscription
Expand Down

0 comments on commit 2802b8e

Please sign in to comment.