SlideShare a Scribd company logo
Spring-WebSocket 기반
Full-Featured 채팅 구현
실시간 웹
소셜 피드, 알림, 채팅 등
웹의 진화
HTTP 1.1 > Ajax > WebSocket > HTTP/ 2
이벤트기반 응답의 구현 방
법
Polling
Ajax + setInterval
Comet (Ajax Push)
Long Polling
HTTP Streaming
WebSocket
HTTP 포트를 사용하는 TCP 상의 쌍방향 통신
WebSocket API
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
var ws = new WebSocket(‘ws://localhost/ws');
ws.onopen = function() {
ws.send(‘hello’);
};
ws.onmessage = function(e) {
console.log(‘message’, e.data);
};
ws.onclose = function(e) {
console.log(‘close’, e.code);
};
SockJS
웹소켓(형) 객체를 제공하는 cross-browser 라이브러리
https://github.com/sockjs/sockjs-client
var sock = new SockJS(‘ws://localhost/ws');
sock.onopen = function() {
sock.send(‘hello’);
};
sock.onmessage = function(e) {
console.log(‘message’, e.data);
};
sock.onclose = function() {
console.log(‘close’);
};
STOMP
웹소켓 서브 프로토콜
Spring WebSocket 에서 지원
stomp.js
var sock = new SockJS(‘ws://localhost/ws');
var client = Stomp.over(sock);
client.connect({}, function() {
client.subscribe("/topic/test", function(message) {
console.log(message);
});
});
client.send("/topic/test", {}, "Hello, STOMP");
client.disconnect(function() {
console.log('disconnected.');
};
Spring WebSocket
Spring-WebSocket 기반 Full-Featured 채팅 구현
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint(“/sockjs").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.setApplicationDestinationPrefixes("/app");
config.enableSimpleBroker("/topic", "/queue");
}
}
@Controller
public class MessageController {
@MessageMapping("/app")
@SendTo("/topic/test")
public CommentView send(String message) {
return message
}
}
Scaling
BrokerRelay로 전환
현재 접속 사용자 및 구독 상태 기록
Spring-WebSocket 기반 Full-Featured 채팅 구현
RabbitMQ
브로커로 사용
STOMP 플러그인 지원
MultiServerUserRegistry
@Autowired
SimpUserRegistry userRegistry;
final String dest = stompHeaderAccessor.getDestination();
userRegistry.findSubscriptions(s -> s.getDestination().equals(dest)).size();
Security
Spring Security 필터
Handshake 과정에서 HTTP 요청에 적용
끝

More Related Content

Similar to Spring-WebSocket 기반 Full-Featured 채팅 구현 (20)

PDF
막하는 스터디 첫 번째 만남 Node.js
연웅 조
 
PPTX
Startup JavaScript 9 - Socket.IO 실시간 통신
Circulus
 
PDF
vert.x 를 활용한 분산서버 개발하기
John Kim
 
PDF
Jung jaeyeoup
ssuser2a0d74
 
PDF
챗봇 시작해보기
성일 한
 
PDF
Python 으로 Slackbot 개발하기
성일 한
 
PDF
채팅 소스부터 Https 주소까지
Kenu, GwangNam Heo
 
PDF
Node.js 첫걸음
SeungHyun Lee
 
PPTX
TCP echo 서버 및 클라이언트 예제 스터디
quxn6
 
PPTX
.net core 에서 SignalR 사용해보기
Ji Lee
 
PDF
.NET에서 비동기 프로그래밍 배우기
Seong Won Mun
 
PPTX
자바 다중 채팅 프로그램
Hwangcy
 
PDF
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
John Kim
 
PDF
AWS Meetup 프리젠테이션.pdf
AlexLee226686
 
PDF
[개방형 클라우드 플랫폼 오픈세미나 오픈클라우드 Pub] 3.open shift 분석
Tommy Lee
 
PDF
Mozilla 오픈 웹 모바일 플랫폼 (2012)
Channy Yun
 
PDF
Spring 4.x Web Application 살펴보기
Ji Heon Kim
 
PPTX
[명우니닷컴]웹보안채팅 Isyouchat
Myeongun Ryu
 
PDF
파이썬 웹 프로그래밍 2탄
SeongHyun Ahn
 
PDF
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)
Wonseok Jang
 
막하는 스터디 첫 번째 만남 Node.js
연웅 조
 
Startup JavaScript 9 - Socket.IO 실시간 통신
Circulus
 
vert.x 를 활용한 분산서버 개발하기
John Kim
 
Jung jaeyeoup
ssuser2a0d74
 
챗봇 시작해보기
성일 한
 
Python 으로 Slackbot 개발하기
성일 한
 
채팅 소스부터 Https 주소까지
Kenu, GwangNam Heo
 
Node.js 첫걸음
SeungHyun Lee
 
TCP echo 서버 및 클라이언트 예제 스터디
quxn6
 
.net core 에서 SignalR 사용해보기
Ji Lee
 
.NET에서 비동기 프로그래밍 배우기
Seong Won Mun
 
자바 다중 채팅 프로그램
Hwangcy
 
NODE.JS 글로벌 기업 적용 사례 그리고, real-time 어플리케이션 개발하기
John Kim
 
AWS Meetup 프리젠테이션.pdf
AlexLee226686
 
[개방형 클라우드 플랫폼 오픈세미나 오픈클라우드 Pub] 3.open shift 분석
Tommy Lee
 
Mozilla 오픈 웹 모바일 플랫폼 (2012)
Channy Yun
 
Spring 4.x Web Application 살펴보기
Ji Heon Kim
 
[명우니닷컴]웹보안채팅 Isyouchat
Myeongun Ryu
 
파이썬 웹 프로그래밍 2탄
SeongHyun Ahn
 
Progressive Web App(PWA) 테코톡 발표자료 - 마르코(장원석)
Wonseok Jang
 

Spring-WebSocket 기반 Full-Featured 채팅 구현