Handle STOMP messages to user destination in order

Closes gh-31395
This commit is contained in:
rstoyanchev
2023-10-11 12:14:39 +01:00
parent 9eb39e182e
commit 3277b0d6ac
9 changed files with 219 additions and 25 deletions

View File

@@ -6,7 +6,7 @@ written to WebSocket sessions. As the channel is backed by a `ThreadPoolExecutor
are processed in different threads, and the resulting sequence received by the client may
not match the exact order of publication.
If this is an issue, enable the `setPreservePublishOrder` flag, as the following example shows:
To enable ordered publishing, set the `setPreservePublishOrder` flag as follows:
[source,java,indent=0,subs="verbatim,quotes"]
----
@@ -47,5 +47,22 @@ When the flag is set, messages within the same client session are published to t
`clientOutboundChannel` one at a time, so that the order of publication is guaranteed.
Note that this incurs a small performance overhead, so you should enable it only if it is required.
The same also applies to messages from the client, which are sent to the `clientInboundChannel`,
from where they are handled according to their destination prefix. As the channel is backed by
a `ThreadPoolExecutor`, messages are processed in different threads, and the resulting sequence
of handling may not match the exact order in which they were received.
To enable ordered publishing, set the `setPreserveReceiveOrder` flag as follows:
[source,java,indent=0,subs="verbatim,quotes"]
----
@Configuration
@EnableWebSocketMessageBroker
public class MyConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.setPreserveReceiveOrder(true);
}
}
----