@@ -1470,10 +1470,10 @@ cloud-based STOMP service.
1470
1470
[[websocket-stomp-destination-separator]]
1471
1471
=== Dot as Separator
1472
1472
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 .
1477
1477
1478
1478
In Java config:
1479
1479
@@ -1488,14 +1488,14 @@ In Java config:
1488
1488
1489
1489
@Override
1490
1490
public void configureMessageBroker(MessageBrokerRegistry registry) {
1491
- registry.enableStompBrokerRelay("/queue/", "/topic/");
1491
+ registry.setPathMatcher(**new AntPathMatcher("."));**
1492
+ registry.enableStompBrokerRelay("/queue", "/topic");
1492
1493
registry.setApplicationDestinationPrefixes("/app");
1493
- registry.setPathMatcher(new AntPathMatcher("."));
1494
1494
}
1495
1495
}
1496
1496
----
1497
1497
1498
- In XML config :
1498
+ In XML:
1499
1499
1500
1500
[source,xml,indent=0]
1501
1501
[subs="verbatim,quotes,attributes"]
@@ -1509,19 +1509,21 @@ In XML config:
1509
1509
http://www.springframework.org/schema/websocket
1510
1510
http://www.springframework.org/schema/websocket/spring-websocket.xsd">
1511
1511
1512
- <websocket:message-broker application-destination-prefix="/app" path-matcher="pathMatcher">
1512
+ <websocket:message-broker application-destination-prefix="/app" path-matcher="** pathMatcher** ">
1513
1513
<websocket:stomp-endpoint path="/stomp"/>
1514
- <websocket:simple -broker prefix="/topic, /queue"/>
1514
+ <websocket:stomp -broker-relay prefix="/topic,/queue" />
1515
1515
</websocket:message-broker>
1516
1516
1517
+ **
1517
1518
<bean id="pathMatcher" class="org.springframework.util.AntPathMatcher">
1518
1519
<constructor-arg index="0" value="."/>
1519
1520
</bean>
1521
+ **
1520
1522
1521
1523
</beans>
1522
1524
----
1523
1525
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 :
1525
1527
1526
1528
[source,java,indent=0]
1527
1529
[subs="verbatim,quotes"]
@@ -1537,7 +1539,15 @@ And below is a simple example to illustrate a controller with "." separator:
1537
1539
}
1538
1540
----
1539
1541
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.
1541
1551
1542
1552
1543
1553
0 commit comments