Skip to content

elixter/chatAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chatAPI

설명

라인에선 고속 병행 처리를 위해 Akka라는 것을 사용했으나 Go언어만을 사용해서 구축하였다. 각 구성요소에 해당하는 부분은 다음과 같다.

  • at Line system => my system
    • UserActor => Client struct
    • ChatRoomActor => Room struct
    • ChatSupervisor => Hub struct

기술스택

  • Go
  • MySQL
  • Redis

TODO

  • 기본 기능

  • 서버간 동기화

  • 고루틴 누수 방지 코드 재설계

    • 널리 사용되는 패턴은 사용하지 않았지만 잔여 고루틴 없음
  • 메세지 타입별 처리

    • 이미지 데이터 처리
  • 채팅방 관리 API

  • JSON 인코딩 벤치마크

    • 다른 방식으로 해봤지만 큰 차이가 없어서 기존 방식 사용
    • 데이터 검증 및 송수신에서 JSON 인코딩/디코딩과 공백구분 문자열 두 가지 방식의 차이는 약 0.0003~0.0004ns

실행

  • 프로젝트 Root directory에 다음과 같이 config.json 파일 생성

    {
     "db": {
       "id": "",
       "password": "",
       "host": "",
       "port": "",
       "database": "",
     },
     "mq": {
       "host": "",
       "port": "",
       "id": "",
       "password": "",
       "listeningQueueName": ""
     },
     "redis": {
       "id":"",
       "password": "",
       "host": "",
       "port": "",
       "database": "",
       "listeningChannelName": "",
       "publishChannelName": ""
     },
     "logger": {
       "level": ""
     }
    }
  • 클라이언트에서 다음 URL로 소켓 연결

    ws://hostname:8080/ws/:roomId
    
    • 예제 (javascript)
    // 연결
    conn = new WebSocket("ws://localhost:8080/ws/123");
    
    // 메세지 전송
    now = new Date(Date.now());
    conn.send(JSON.stringify({
        message_type: "chat_txt",
        author_id: 11,
        room_id: 123,
        content: msg.value,
        create_at: now.toISOString(),
    }));

소켓 데이터 포맷 (json)

 {
   "message_type": message type : "chat_txt" or "chat_img"
   "author_id": integer value for user id
   "room_id": integer value for chatting room id
   "content": chatting content
   "create_at": UTC timestamp
 }

Demo

Hnet-image

About

채팅 API를 만들어 보아요

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published