
類別
###演示


https://im.cookeem.com
更改為cookim目錄,在下面運行命令,以Docker組合模式啟動多個節點Cookim服務器。這樣,將啟動3個容器:mongo,cookim1和cookim2
$ git clone https://github.com/cookeem/CookIM.git
$ cd CookIM
$ sudo docker-compose up -d
Creating mongo
Creating cookim1
Creating cookim2運行Docker作曲後,使用不同的瀏覽器訪問下面的URL以連接到Cookim1和Cookim2
http:// localhost:8080 http:// localhost:8081
類別
您可以在docker-compose.yml中添加config(在cookim目錄中)以添加cookim服務器節點,此示例顯示瞭如何在docker組成中添加cookim3:
cookim3 :
image : cookeem/cookim
container_name : cookim3
hostname : cookim3
environment :
HOST_NAME : cookim3
WEB_PORT : 8080
AKKA_PORT : 2551
SEED_NODES : cookim1:2551
MONGO_URI : mongodb://mongo:27017/local
ports :
- " 8082:8080 "
depends_on :
- mongo
- cookim1類別
查看容器cookim1
$ sudo docker logs -f cookim1執行到容器cookim1進行調試
$ sudo docker exec -ti cookim1 bash類別
$ sudo docker-compose stop
$ sudo docker-compose rm類別
類別
git clone https://github.com/cookeem/CookIM.git
cd CookIM類別
配置文件位於conf/application.conf上,請確保您的mongodb uri配置。
mongodb {
dbname = " cookim "
uri = " mongodb://mongo:27017/local "
} cookim的組裝cookim項目到fatjar,target jar位於target/scala-2.11/CookIM-assembly-0.2.0-SNAPSHOT.jar
sbt clean assembly類別
Cookim使用MongoDB存儲聊天消息和用戶數據,請確保您在啟動Cookim之前啟動MongoDB。
有兩種啟動cookim服務器的方法:SBT和Java
一個。 SBT調試方式:
$ cd # CookIM directory#
$ sbt " run-main com.cookeem.chat.CookIM -h localhost -w 8080 -a 2551 -s localhost:2551 "b。包裝並編譯脂肪罐:
$ sbt assemblyc。 Java生產方式:
$ java -classpath " target/scala-2.11/CookIM-assembly-0.2.4-SNAPSHOT.jar " com.cookeem.chat.CookIM -h localhost -w 8080 -a 2551 -s localhost:2551上面的命令已啟動Web服務器收聽端口8080和Akka系統聽端口2551
參數:
-a -h [-m ] [-n] -s -w -a,--akka-port akka cluster node port -h,--host-name current web service external host name -m,--mongo-uri mongodb connection uri, example: mongodb://localhost:27017/local -n,--nat is nat network or in docker -s,--seed-nodes akka cluster seed節點,與逗號分開,示例:localhost:2551,localhost:2552 -W, - Web-Port Web服務端口
類別
http:// localhost:8080
類別
打開另一個終端,啟動另一台Cookim服務器以測試服務器之間的消息通信:
一個。 SBT調試方式:
$ sbt " run-main com.cookeem.chat.CookIM -h localhost -w 8081 -a 2552 -s localhost:2551 "b。 Java生產方式:
$ java -classpath " target/scala-2.11/CookIM-assembly-0.2.0-SNAPSHOT.jar " com.cookeem.chat.CookIM -h localhost -w 8081 -a 2552 -s localhost:2551上面的命令已啟動Web服務器收聽端口8081和Akka系統聽端口2552
類別
http:// localhost:8081
類別

** Cookim服務器從3個部分製作:**
- Akka HTTP:提供Web服務,Websocket的瀏覽器連接分佈式聊天服務器
- Akka流:Akka HTTP接收WebSocket消息(WebSocket消息包括TextMessage和BinaryMessage),然後通過Akka Stream Way將消息發送到ChatService,Websocket Inception Include JWT(JavaScript Web Token),如果JWT verify Failify Failify Failify Failify失敗,ChatService流chatservice流將返回拒絕消息;如果JWT驗證成功,ChatService流將向ChatSessionActor發送消息
- Akka群集:Akka Stream發送WebSocke消息到Akka cluster ChatSessionActor,ChatSessionActor使用DistribtionPubSub在Akka cluster中訂閱和發布消息。當用戶在線會話時,它將訂閱會話;當用戶在會話中發送消息時,它將在Akka群集中發布消息,訂閱會話的參與者將接收發布消息
類別

- WebSocket消息主體包括JWT,FlowFromws用於接收WebSocket消息並解碼JWT;
- 當JWT驗證故障時,它將廣播以過濾以濾波以過濾以失敗消息;當JWT驗證成功時,它將廣播到FilterSuccess過濾到成功消息;
- 當創建Akka流時,Builder.MaterializedValue將發送消息到ConnectedWs,ConnectedWs轉換消息接收到UserOnline消息,然後發送到ChatSinkactor最終發送到ChatSessionActor;
- ChatActorSink將消息發送給ChatSessionActor,當Akka流關閉時,如果將UserOffline消息發送到Down流;
- ChatSource從ChatSessionActor接收消息,然後將消息發送回FlowAcpppedback;
- flowAcppenT背式背面將使Websocket連接keepalive;
- Flow Repreject和FlowAcppeedback消息最終發送到Flofbackws,FrowBackws將消息轉換為WebSocket格式,然後發送回用戶;
類別
*login (login email)
nickname (nickname)
password (password SHA1)
gender (gender: unknow:0, boy:1, girl:2)
avatar (avatar abs path, example: /upload/avatar/201610/26/xxxx.JPG)
lastLogin (last login timestamp)
loginCount (login counts)
sessionsStatus (user joined sessions status)
[{sessionid: session id, newCount: unread message count in this session}]
friends (user's friends list: [friends uid])
dateline (register timestamp)
*createuid (creator uid)
*ouid (receiver uid, when session type is private available)
sessionIcon (session icon, when session type is group available)
sessionType (session type: 0:private, 1:group)
publicType (public type: 0:not public, 1:public)
sessionName (session name)
dateline (created timestamp)
usersStatus (users who joined this session status)
[{uid: uid, online: (true, false)}]
lastMsgid (last message id)
lastUpdate (last update timestamp)
*uid (send user uid)
*sessionid (relative session id)
msgType (message type)
content (message content)
fileInfo (file information)
{
filePath
fileName
fileType
fileSize
fileThumb
}
*dateline (created timestamp)
*uid (online user id)
dateline (last update timestamp)
noticeType (notification type: "joinFriend", "removeFriend", "inviteSession")
senduid (send user id)
*recvuid (receive user id)
sessionid (relative session id)
isRead (notification is read: 0:not read, 1:already read)
dateline (created timestamp)
類別
有兩個WebSocket頻道:WS-PUSH和WS-CHAT
ws-push向用戶發送會話新消息,當用戶不在線會話時,他們仍然可以收到哪些會話有新消息
/WS-PUSH頻道
up message, use to subscribe push message:
{ userToken: "xxx" }
down message:
acceptMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "accept", content: "xxx", dateline: "xxx" }
rejectMsg: { uid: "", nickname: "", avatar: "", sessionid: "", sessionName: "", sessionIcon: "", msgType: "reject", content: "xxx", dateline: "xxx" }
keepAlive: { uid: "", nickname: "", avatar: "", sessionid: "", sessionName: "", sessionIcon: "", msgType: "keepalive", content: "", dateline: "xxx" }
textMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "text", content: "xxx", dateline: "xxx" }
fileMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "file", fileName: "xxx", fileType: "xxx", fileid: "xxx", thumbid: "xxx", dateline: "xxx" }
onlineMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "online", content: "xxx", dateline: "xxx" }
offlineMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "offline", content: "xxx", dateline: "xxx" }
joinSessionMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "join", content: "xxx", dateline: "xxx" }
leaveSessionMsg:{ uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "leave", content: "xxx", dateline: "xxx" }
noticeMsg: { uid: "", nickname: "", avatar: "", sessionid: "", sessionName: "xxx", sessionIcon: "xxx", msgType: "system", content: "xxx", dateline: "xxx" }
message push to browser:
pushMsg: {
uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "xxx",
content: "xxx", fileName: "xxx", fileType: "xxx", fileid: "xxx", thumbid: "xxx",
dateline: "xxx"
}
類別
WS-CHAT是會話聊天頻道,用戶在此頻道中發送和接收會話消息
/ws-chat channel
up message:
onlineMsg: { userToken: "xxx", sessionToken: "xxx", msgType:"online", content:"" }
textMsg: { userToken: "xxx", sessionToken: "xxx", msgType:"text", content:"xxx" }
fileMsg: { userToken: "xxx", sessionToken: "xxx", msgType:"file", fileName:"xxx", fileSize: 999, fileType: "xxx" }<#BinaryInfo#>binary_file_array_buffer
down message:
rejectMsg: { uid: "", nickname: "", avatar: "", sessionid: "", sessionName: "", sessionIcon: "", msgType: "reject", content: "xxx", dateline: "xxx" }
keepAlive: { uid: "", nickname: "", avatar: "", sessionid: "", sessionName: "", sessionIcon: "", msgType: "keepalive", content: "", dateline: "xxx" }
textMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "text", content: "xxx", dateline: "xxx" }
fileMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "file", fileName: "xxx", fileType: "xxx", fileid: "xxx", thumbid: "xxx", dateline: "xxx" }
onlineMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "online", content: "xxx", dateline: "xxx" }
offlineMsg: { uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "offline", content: "xxx", dateline: "xxx" }
joinSessionMsg:{ uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "join", content: "xxx", dateline: "xxx" }
leaveSessionMsg:{ uid: "xxx", nickname: "xxx", avatar: "xxx", sessionid: "xxx", sessionName: "xxx", sessionIcon: "xxx", msgType: "leave", content: "xxx", dateline: "xxx" }
noticeMsg: { uid: "", nickname: "", avatar: "", sessionid: "", sessionName: "xxx", sessionIcon: "xxx", msgType: "system", content: "xxx", dateline: "xxx" }
message push to browser:
chatMsg: {
uid: "xxx", nickname: "xxx", avatar: "xxx", msgType: "xxx",
content: "xxx", fileName: "xxx", fileType: "xxx", fileid: "xxx", thumbid: "xxx",
dateline: "xxx"
}
類別
類別
類別
類別