From 445c0def0ce741e70d716da74862e03a4524ab3f Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 29 Nov 2021 17:13:57 +0000 Subject: [PATCH 1/2] Update docs on heartbeats with simple broker Closes gh-27746 --- src/docs/asciidoc/web/websocket.adoc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/docs/asciidoc/web/websocket.adoc b/src/docs/asciidoc/web/websocket.adoc index e4ee1e49c05..2a8042403d5 100644 --- a/src/docs/asciidoc/web/websocket.adoc +++ b/src/docs/asciidoc/web/websocket.adoc @@ -1439,8 +1439,11 @@ See <>. If configured with a task scheduler, the simple broker supports https://stomp.github.io/stomp-specification-1.2.html#Heart-beating[STOMP heartbeats]. -For that, you can declare your own scheduler or use the one that is automatically -declared and used internally. The following example shows how to declare your own scheduler: +To configure a scheduler, you can declare your own `TaskScheduler` bean and set it through +the `MessageBrokerRegistry`. Alternatively, you can use the one that is automatically +declared in the built-in WebSocket configuration, however, you'll' need `@Lazy` to avoid +a cycle between the built-in WebSocket configuration and your +`WebSocketMessageBrokerConfigurer`. For example: [source,java,indent=0,subs="verbatim,quotes"] ---- @@ -1451,13 +1454,12 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { private TaskScheduler messageBrokerTaskScheduler; @Autowired - public void setMessageBrokerTaskScheduler(TaskScheduler taskScheduler) { + public void setMessageBrokerTaskScheduler(@Lazy TaskScheduler taskScheduler) { this.messageBrokerTaskScheduler = taskScheduler; } @Override public void configureMessageBroker(MessageBrokerRegistry registry) { - registry.enableSimpleBroker("/queue/", "/topic/") .setHeartbeatValue(new long[] {10000, 20000}) .setTaskScheduler(this.messageBrokerTaskScheduler); From 0d478ca8dd55d080e656831f9abc7fa794d7acfb Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 29 Nov 2021 17:37:37 +0000 Subject: [PATCH 2/2] Add link to WebSocket scope from the Spring Core section Closes gh-25172 --- src/docs/asciidoc/core/core-beans.adoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/docs/asciidoc/core/core-beans.adoc b/src/docs/asciidoc/core/core-beans.adoc index 22cdf42ce53..72138867377 100644 --- a/src/docs/asciidoc/core/core-beans.adoc +++ b/src/docs/asciidoc/core/core-beans.adoc @@ -2969,6 +2969,8 @@ When using annotation-driven components or Java configuration, you can use the ---- + + [[beans-factory-scopes-application]] ==== Application Scope @@ -3012,6 +3014,17 @@ following example shows how to do so: + +[[beans-factory-scopes-websocket]] +==== WebSocket Scope + +WebSocket scope is associated with the lifecycle of a WebSocket session and applies to +STOMP over WebSocket applications, see +<> for more details. + + + + [[beans-factory-scopes-other-injection]] ==== Scoped Beans as Dependencies