@@ -1645,10 +1645,10 @@ cloud-based STOMP service.
1645
1645
[[websocket-stomp-destination-separator]]
1646
1646
=== Dot as Separator
1647
1647
1648
- Although slash-separated path patterns are familiar to web developers, in messaging
1649
- it is common to use a ". " as the separator, for example in the names of topics, queues,
1650
- exchanges, etc. Applications can also switch to using "." (dot) instead of "/" (slash)
1651
- as the separator in `@MessageMapping` mappings by configuring a custom `AntPathMatcher` .
1648
+ When messages are routed to `@MessageMapping` methods, they're matched with
1649
+ `AntPathMatcher` and by default patterns are expected to use slash "/ " as separator.
1650
+ This is a good convention in a web applications and similar to HTTP URLs. However if
1651
+ you are more used to messaging conventions, you can switch to using dot "." as separator .
1652
1652
1653
1653
In Java config:
1654
1654
@@ -1657,20 +1657,20 @@ In Java config:
1657
1657
----
1658
1658
@Configuration
1659
1659
@EnableWebSocketMessageBroker
1660
- public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
1660
+ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
1661
1661
1662
1662
// ...
1663
1663
1664
1664
@Override
1665
1665
public void configureMessageBroker(MessageBrokerRegistry registry) {
1666
- registry.enableStompBrokerRelay("/queue/", "/topic/");
1666
+ registry.setPathMatcher(**new AntPathMatcher("."));**
1667
+ registry.enableStompBrokerRelay("/queue", "/topic");
1667
1668
registry.setApplicationDestinationPrefixes("/app");
1668
- registry.setPathMatcher(new AntPathMatcher("."));
1669
1669
}
1670
1670
}
1671
1671
----
1672
1672
1673
- In XML config :
1673
+ In XML:
1674
1674
1675
1675
[source,xml,indent=0]
1676
1676
[subs="verbatim,quotes,attributes"]
@@ -1684,19 +1684,21 @@ In XML config:
1684
1684
http://www.springframework.org/schema/websocket
1685
1685
http://www.springframework.org/schema/websocket/spring-websocket.xsd">
1686
1686
1687
- <websocket:message-broker application-destination-prefix="/app" path-matcher="pathMatcher">
1687
+ <websocket:message-broker application-destination-prefix="/app" path-matcher="** pathMatcher** ">
1688
1688
<websocket:stomp-endpoint path="/stomp"/>
1689
- <websocket:simple -broker prefix="/topic, /queue"/>
1689
+ <websocket:stomp -broker-relay prefix="/topic,/queue" />
1690
1690
</websocket:message-broker>
1691
1691
1692
+ **
1692
1693
<bean id="pathMatcher" class="org.springframework.util.AntPathMatcher">
1693
1694
<constructor-arg index="0" value="."/>
1694
1695
</bean>
1696
+ **
1695
1697
1696
1698
</beans>
1697
1699
----
1698
1700
1699
- And below is a simple example to illustrate a controller with "." separator:
1701
+ After that a controller may use dot "." as separator in `@MessageMapping` methods :
1700
1702
1701
1703
[source,java,indent=0]
1702
1704
[subs="verbatim,quotes"]
@@ -1712,7 +1714,15 @@ And below is a simple example to illustrate a controller with "." separator:
1712
1714
}
1713
1715
----
1714
1716
1715
- If the application prefix is set to "/app" then the foo method is effectively mapped to "/app/foo.bar.{baz}".
1717
+ The client can now send a message to `"/app/foo.bar.baz123"`.
1718
+
1719
+ In the example above we did not change the prefixes on the "broker relay" because those
1720
+ depend entirely on the external message broker. Check the STOMP documentation pages of
1721
+ the broker you're using to see what conventions it supports for the destination header.
1722
+
1723
+ The "simple broker" on the other hand does rely on the configured `PathMatcher` so if
1724
+ you switch the separator that will also apply to the broker and the way matches
1725
+ destinations from a message to patterns in subscriptions.
1716
1726
1717
1727
1718
1728
0 commit comments