Skip to content

Commit aea6bb6

Browse files
committed
Update STOMP docs on using dot as separator
Issue: SPR-16275
1 parent 0fb31c5 commit aea6bb6

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/docs/asciidoc/web/websocket.adoc

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,10 @@ cloud-based STOMP service.
14701470
[[websocket-stomp-destination-separator]]
14711471
=== Dot as Separator
14721472

1473-
Although slash-separated path patterns are familiar to web developers, in messaging
1474-
it is common to use a "." as the separator, for example in the names of topics, queues,
1475-
exchanges, etc. Applications can also switch to using "." (dot) instead of "/" (slash)
1476-
as the separator in `@MessageMapping` mappings by configuring a custom `AntPathMatcher`.
1473+
When messages are routed to `@MessageMapping` methods, they're matched with
1474+
`AntPathMatcher` and by default patterns are expected to use slash "/" as separator.
1475+
This is a good convention in a web applications and similar to HTTP URLs. However if
1476+
you are more used to messaging conventions, you can switch to using dot "." as separator.
14771477

14781478
In Java config:
14791479

@@ -1488,14 +1488,14 @@ In Java config:
14881488
14891489
@Override
14901490
public void configureMessageBroker(MessageBrokerRegistry registry) {
1491-
registry.enableStompBrokerRelay("/queue/", "/topic/");
1491+
registry.setPathMatcher(**new AntPathMatcher("."));**
1492+
registry.enableStompBrokerRelay("/queue", "/topic");
14921493
registry.setApplicationDestinationPrefixes("/app");
1493-
registry.setPathMatcher(new AntPathMatcher("."));
14941494
}
14951495
}
14961496
----
14971497

1498-
In XML config:
1498+
In XML:
14991499

15001500
[source,xml,indent=0]
15011501
[subs="verbatim,quotes,attributes"]
@@ -1509,19 +1509,21 @@ In XML config:
15091509
http://www.springframework.org/schema/websocket
15101510
http://www.springframework.org/schema/websocket/spring-websocket.xsd">
15111511
1512-
<websocket:message-broker application-destination-prefix="/app" path-matcher="pathMatcher">
1512+
<websocket:message-broker application-destination-prefix="/app" path-matcher="**pathMatcher**">
15131513
<websocket:stomp-endpoint path="/stomp"/>
1514-
<websocket:simple-broker prefix="/topic, /queue"/>
1514+
<websocket:stomp-broker-relay prefix="/topic,/queue" />
15151515
</websocket:message-broker>
15161516
1517+
**
15171518
<bean id="pathMatcher" class="org.springframework.util.AntPathMatcher">
15181519
<constructor-arg index="0" value="."/>
15191520
</bean>
1521+
**
15201522
15211523
</beans>
15221524
----
15231525

1524-
And below is a simple example to illustrate a controller with "." separator:
1526+
After that a controller may use dot "." as separator in `@MessageMapping` methods:
15251527

15261528
[source,java,indent=0]
15271529
[subs="verbatim,quotes"]
@@ -1537,7 +1539,15 @@ And below is a simple example to illustrate a controller with "." separator:
15371539
}
15381540
----
15391541

1540-
If the application prefix is set to "/app" then the foo method is effectively mapped to "/app/foo.bar.{baz}".
1542+
The client can now send a message to `"/app/foo.bar.baz123"`.
1543+
1544+
In the example above we did not change the prefixes on the "broker relay" because those
1545+
depend entirely on the external message broker. Check the STOMP documentation pages of
1546+
the broker you're using to see what conventions it supports for the destination header.
1547+
1548+
The "simple broker" on the other hand does rely on the configured `PathMatcher` so if
1549+
you switch the separator that will also apply to the broker and the way matches
1550+
destinations from a message to patterns in subscriptions.
15411551

15421552

15431553

0 commit comments

Comments
 (0)