Created
May 14, 2019 21:34
-
-
Save john-nash-rs/73c3193099202d7d34d8790631a0918c to your computer and use it in GitHub Desktop.
Spring allows us to create a configuration class that enables the project as WebSocket Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nulpointerexception.npechatroom; | |
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 WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { | |
/** | |
* | |
* @param config | |
* Here we have enabled simple in memory message broker. We can register rabbit MQ also as message broker | |
* by using the MessageBrokerRegistry config methods/ | |
*/ | |
@Override | |
public void configureMessageBroker(MessageBrokerRegistry config) { | |
config.enableSimpleBroker("/chat-room"); | |
config.setApplicationDestinationPrefixes("/chat-app"); | |
} | |
@Override | |
public void registerStompEndpoints(StompEndpointRegistry registry) { | |
registry.addEndpoint("/sock").setAllowedOrigins("*").withSockJS(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment