Skip to content

Commit b695b15

Browse files
committed
Update STOMP docs on using dot as separator
Issue: SPR-16275
1 parent ef4b62c commit b695b15

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/asciidoc/web-websocket.adoc

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,10 +1645,10 @@ cloud-based STOMP service.
16451645
[[websocket-stomp-destination-separator]]
16461646
=== Dot as Separator
16471647

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.
16521652

16531653
In Java config:
16541654

@@ -1657,20 +1657,20 @@ In Java config:
16571657
----
16581658
@Configuration
16591659
@EnableWebSocketMessageBroker
1660-
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
1660+
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
16611661
16621662
// ...
16631663
16641664
@Override
16651665
public void configureMessageBroker(MessageBrokerRegistry registry) {
1666-
registry.enableStompBrokerRelay("/queue/", "/topic/");
1666+
registry.setPathMatcher(**new AntPathMatcher("."));**
1667+
registry.enableStompBrokerRelay("/queue", "/topic");
16671668
registry.setApplicationDestinationPrefixes("/app");
1668-
registry.setPathMatcher(new AntPathMatcher("."));
16691669
}
16701670
}
16711671
----
16721672

1673-
In XML config:
1673+
In XML:
16741674

16751675
[source,xml,indent=0]
16761676
[subs="verbatim,quotes,attributes"]
@@ -1684,19 +1684,21 @@ In XML config:
16841684
http://www.springframework.org/schema/websocket
16851685
http://www.springframework.org/schema/websocket/spring-websocket.xsd">
16861686
1687-
<websocket:message-broker application-destination-prefix="/app" path-matcher="pathMatcher">
1687+
<websocket:message-broker application-destination-prefix="/app" path-matcher="**pathMatcher**">
16881688
<websocket:stomp-endpoint path="/stomp"/>
1689-
<websocket:simple-broker prefix="/topic, /queue"/>
1689+
<websocket:stomp-broker-relay prefix="/topic,/queue" />
16901690
</websocket:message-broker>
16911691
1692+
**
16921693
<bean id="pathMatcher" class="org.springframework.util.AntPathMatcher">
16931694
<constructor-arg index="0" value="."/>
16941695
</bean>
1696+
**
16951697
16961698
</beans>
16971699
----
16981700

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:
17001702

17011703
[source,java,indent=0]
17021704
[subs="verbatim,quotes"]
@@ -1712,7 +1714,15 @@ And below is a simple example to illustrate a controller with "." separator:
17121714
}
17131715
----
17141716

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.
17161726

17171727

17181728

0 commit comments

Comments
 (0)