feat: websocket config endpoints
This commit is contained in:
parent
ba3775f42b
commit
dcb76612d5
1 changed files with 33 additions and 0 deletions
33
server/src/main/java/server/WebSocketConfig.java
Normal file
33
server/src/main/java/server/WebSocketConfig.java
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
package server;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||||
|
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||||
|
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSocketMessageBroker
|
||||||
|
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||||
|
@Override
|
||||||
|
public void configureMessageBroker(MessageBrokerRegistry registry) {
|
||||||
|
|
||||||
|
// SUBSCRIBE /subscribe/{mapping}, see UpdateMessagingController definition
|
||||||
|
// adds a broker endpoint subscribers listen to
|
||||||
|
registry.enableSimpleBroker("/subscribe");
|
||||||
|
|
||||||
|
// SEND /send/updates/{mapping}, see UpdateMessagingController definition
|
||||||
|
// the client pushes a new message to this address
|
||||||
|
registry.setApplicationDestinationPrefixes("/send");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||||
|
// a client can now push data to /send/updates/{mapping}, see UpdateMessagingController
|
||||||
|
// allow access from any origin: one server, many clients
|
||||||
|
registry.addEndpoint("/updates").setAllowedOrigins("*");
|
||||||
|
// optional, recommended to increase browser & networking support
|
||||||
|
registry.addEndpoint("/updates").setAllowedOrigins("*").withSockJS();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue