-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSocketConfiguration.java
More file actions
42 lines (37 loc) · 1.62 KB
/
WebSocketConfiguration.java
File metadata and controls
42 lines (37 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.example.chatapplication.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.session.web.socket.config.annotation.AbstractSessionWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@Configuration
@EnableScheduling
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractSessionWebSocketMessageBrokerConfigurer {
@Value("${chat.app.relay.host}")
private String relayHost;
@Value("${chat.app.relay.port}")
private int relayPort;
@Value("${chat.app.relay.username}")
private String username;
@Value("${chat.app.relay.password}")
private String password;
@Override
protected void configureStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/room");
registry.enableStompBrokerRelay("/topic/", "/queue/")
.setRelayHost(relayHost)
.setRelayPort(relayPort)
.setSystemLogin(username)
.setSystemPasscode(password)
.setClientLogin(username)
.setClientPasscode(password);
}
}