@@ -1880,6 +1880,60 @@ of the `message-broker` element in XML.
1880
1880
1881
1881
1882
1882
1883
+ [[websocket-stomp-ordered-messages]]
1884
+ === Order of Messages
1885
+
1886
+ Messages from the broker are published to the "clientOutboundChannel" from where they are
1887
+ written to WebSocket sessions. As the channel is backed by a `ThreadPoolExecutor` messages
1888
+ are processed in different threads, and the resulting sequence received by the client may
1889
+ not match the exact order of publication.
1890
+
1891
+ If this is an issue, enable the following flag:
1892
+
1893
+ [source,java,indent=0]
1894
+ [subs="verbatim,quotes"]
1895
+ ----
1896
+ @Configuration
1897
+ @EnableWebSocketMessageBroker
1898
+ public class MyConfig implements WebSocketMessageBrokerConfigurer {
1899
+
1900
+ @Override
1901
+ protected void configureMessageBroker(MessageBrokerRegistry registry) {
1902
+ // ...
1903
+ registry.setPreservePublishOrder(true);
1904
+ }
1905
+
1906
+ }
1907
+ ----
1908
+
1909
+ The same in XML:
1910
+
1911
+ [source,xml,indent=0]
1912
+ [subs="verbatim,quotes,attributes"]
1913
+ ----
1914
+ <beans xmlns="http://www.springframework.org/schema/beans"
1915
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1916
+ xmlns:websocket="http://www.springframework.org/schema/websocket"
1917
+ xsi:schemaLocation="
1918
+ http://www.springframework.org/schema/beans
1919
+ http://www.springframework.org/schema/beans/spring-beans.xsd
1920
+ http://www.springframework.org/schema/websocket
1921
+ http://www.springframework.org/schema/websocket/spring-websocket.xsd">
1922
+
1923
+ <websocket:message-broker preserve-publish-order="true">
1924
+ <!-- ... -->
1925
+ </websocket:message-broker>
1926
+
1927
+ </beans>
1928
+ ----
1929
+
1930
+ When the flag is set, messages within the same client session are published to the
1931
+ "clientOutboundChannel" one at a time, so that the order of publication is guaranteed.
1932
+ Note that this incurs a small performance overhead, so enable it only if required.
1933
+
1934
+
1935
+
1936
+
1883
1937
[[websocket-stomp-appplication-context-events]]
1884
1938
=== Events and Interception
1885
1939
0 commit comments