0

Implementation of the WebSocketMessageBrokerConfigurer must implement two methods. configureMessageBroker is one of them:

public void configureMessageBroker(MessageBrokerRegistry registry) {
            registry.setApplicationDestinationPrefixes("/app")...};

In this example we configured that all messages with "/app" prefix will be routed to @MessageMapping-annotated methods in controller class.

But setApplicationDestinationPrefixes accepts array of the Strings of variable length. How to assign this or that particular method in a controller all of them annotated with @MessageMapping to a specific prefix in case we have several prefixes?

1 Answers1

0

Initially I thought that the answer was to use @MessageMapping not only over the methods but over the controller class as well and have controller-level annotation mapped to the prefixes while method-level annotation - mapped to the lower parts of the route.

I found an example at https://docs.spring.io/spring-framework/docs/4.3.x/spring-framework-reference/html/websocket.html which gave me this idea:

@Controller
@MessageMapping("foo")
public class FooController {

    @MessageMapping("bar.{baz}")
    public void handleBaz(@DestinationVariable String baz) {
    }
}

but then I noticed that such combination addresses the route "/app/foo.bar.{baz}". {baz} is a placeholder here