@@ -1915,6 +1915,60 @@ of the `message-broker` element in XML.
1915
1915
1916
1916
1917
1917
1918
+ [[websocket-stomp-ordered-messages]]
1919
+ === Order of Messages
1920
+
1921
+ Messages from the broker are published to the "clientOutboundChannel" from where they are
1922
+ written to WebSocket sessions. As the channel is backed by a `ThreadPoolExecutor` messages
1923
+ are processed in different threads, and the resulting sequence received by the client may
1924
+ not match the exact order of publication.
1925
+
1926
+ If this is an issue, enable the following flag:
1927
+
1928
+ [source,java,indent=0]
1929
+ [subs="verbatim,quotes"]
1930
+ ----
1931
+ @Configuration
1932
+ @EnableWebSocketMessageBroker
1933
+ public class MyConfig implements WebSocketMessageBrokerConfigurer {
1934
+
1935
+ @Override
1936
+ protected void configureMessageBroker(MessageBrokerRegistry registry) {
1937
+ // ...
1938
+ registry.setPreservePublishOrder(true);
1939
+ }
1940
+
1941
+ }
1942
+ ----
1943
+
1944
+ The same in XML:
1945
+
1946
+ [source,xml,indent=0]
1947
+ [subs="verbatim,quotes,attributes"]
1948
+ ----
1949
+ <beans xmlns="http://www.springframework.org/schema/beans"
1950
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1951
+ xmlns:websocket="http://www.springframework.org/schema/websocket"
1952
+ xsi:schemaLocation="
1953
+ http://www.springframework.org/schema/beans
1954
+ http://www.springframework.org/schema/beans/spring-beans.xsd
1955
+ http://www.springframework.org/schema/websocket
1956
+ http://www.springframework.org/schema/websocket/spring-websocket.xsd">
1957
+
1958
+ <websocket:message-broker preserve-publish-order="true">
1959
+ <!-- ... -->
1960
+ </websocket:message-broker>
1961
+
1962
+ </beans>
1963
+ ----
1964
+
1965
+ When the flag is set, messages within the same client session are published to the
1966
+ "clientOutboundChannel" one at a time, so that the order of publication is guaranteed.
1967
+ Note that this incurs a small performance overhead, so enable it only if required.
1968
+
1969
+
1970
+
1971
+
1918
1972
[[websocket-stomp-appplication-context-events]]
1919
1973
=== Events and Interception
1920
1974
0 commit comments