pomelo服務(wù)端game-server下的config文件夾用于存放配置文件够委,包括pomelo框架的配置文件桑孩、第三方插件的配置文件闻伶、用戶自定義的配置文件渔伯。其中默認(rèn)的配置文件包括:
配置文件 |
描述 |
master.json |
Master主服務(wù)器所使用的配置文件 |
servers.json |
用于定義服務(wù)器集群,Master主服務(wù)器使用尿褪。 |
adminServer.json |
服務(wù)器類型配置 |
dictionary.json |
用于定義路由壓縮的字典配置文件 |
log4js.json |
日志配置 |
服務(wù)器配置
主服務(wù)器配置master.json
$ vim game-server/config/master.json
{
"development": {
"id": "master-server-1", "host": "127.0.0.1", "port": 3005
},
"production": {
"id": "master-server-1", "host": "127.0.0.1", "port": 3005
}
}
master.json主配置文件的字段格式
字段 |
類型 |
為空 |
描述 |
id |
字符串 |
必填 |
Master主服務(wù)器的ID |
host |
字符串 |
必填 |
Master主服務(wù)器的主機(jī)地址 |
port |
數(shù)字 |
必填 |
Master主服務(wù)器的主機(jī)端口 |
args |
字符串 |
可選 |
為node/v8引擎配置的參數(shù)睦擂,比如--debug:5958。 |
服務(wù)器集群配置server.json
$ vim game-server/config/servers.json
{
"development":{
"gate": [
{"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true}
],
"connector": [
{"id": "connector-server-1", "host": "127.0.0.1", "port": 3150, "clientPort": 3010, "frontend": true},
{"id": "connector-server-2", "host": "127.0.0.1", "port": 3151, "clientPort": 3011, "frontend": true}
],
"chat": [
{"id": "chat-server-1", "host": "127.0.0.1", "port": 3250},
{"id": "chat-server-2", "host": "127.0.0.1", "port": 3251},
{"id": "chat-server-3", "host": "127.0.0.1", "port": 3252}
],
"auth": [
{"id": "auth-server-1", "host": "127.0.0.1", "port": 3350},
{"id": "auth-server-2", "host": "127.0.0.1", "port": 3351},
{"id": "auth-server-3", "host": "127.0.0.1", "port": 3352}
]
},
"production":{
"gate": [
{"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true}
],
"connector": [
{"id": "connector-server-1", "host": "127.0.0.1", "port": 3150, "clientPort": 3010, "frontend": true},
{"id": "connector-server-2", "host": "127.0.0.1", "port": 3151, "clientPort": 3011, "frontend": true}
],
"chat": [
{"id": "chat-server-1", "host": "127.0.0.1", "port": 3250},
{"id": "chat-server-2", "host": "127.0.0.1", "port": 3251},
{"id": "chat-server-3", "host": "127.0.0.1", "port": 3252}
],
"auth": [
{"id": "auth-server-1", "host": "127.0.0.1", "port": 3350},
{"id": "auth-server-2", "host": "127.0.0.1", "port": 3351},
{"id": "auth-server-3", "host": "127.0.0.1", "port": 3352}
]
}
}
服務(wù)器集群配置字段選項(xiàng)
字段 |
類型 |
為空 |
描述 |
id |
字符串 |
必填 |
應(yīng)用邏輯服務(wù)器編號(hào) |
host |
字符串 |
必填 |
應(yīng)用邏輯服務(wù)器主機(jī)地址杖玲,支持IP或域名顿仇。 |
port |
數(shù)字 |
可選 |
應(yīng)用邏輯服務(wù)器接收RPC請(qǐng)求時(shí)所使用的端口,對(duì)于后端服務(wù)器來說是必須的摆马。 |
clientPort |
數(shù)字 |
可選 |
前端服務(wù)器幾首客戶都安鏈接啟用的端口臼闻,對(duì)于后端服務(wù)器而言無需配置。 |
frontend |
布爾 |
可選 |
對(duì)于前端服務(wù)器需配置為true囤采,省略不配置則默認(rèn)為false述呐,后端服務(wù)器可省略。 |
max-connections |
數(shù)值 |
可選 |
前端服務(wù)器最大承載鏈接數(shù)量蕉毯,若超過則后續(xù)鏈接會(huì)被connector拒絕乓搬。 |
args |
字符串 |
可選 |
提供給node/v8引擎的參數(shù)選項(xiàng) |
框架配置
pomelo框架設(shè)置的實(shí)現(xiàn)途徑包括兩種,一種是通過配置文件實(shí)現(xiàn)代虾,一種是通過Application.set()
方法進(jìn)行設(shè)置
Application.set()
方法設(shè)置的參數(shù)根據(jù)組件類型而不同
鏈接配置 connectorConfig
app.set('connectorConfig',
{
connector : pomelo.connectors.hybridconnector,
heartbeat : 10,
useProtobuf : false,
useDict : false
});
配置 |
描述 |
connector |
底層使用的通信connector进肯,默認(rèn)使用sioconnector。 |
useProtobuf |
是否開啟消息的protobuf功能褐着,僅支持hybridconnector坷澡。 |
useDict |
是否開啟基于字典的路由消息壓縮,僅支持hybridconnector含蓉。 |
useCrypto |
是否開啟通信時(shí)的數(shù)字簽名频敛,僅支持hybirdconnector。 |
encode/decode |
底層connector消息的編碼解碼函數(shù)馅扣,不提供則使用系統(tǒng)默認(rèn)斟赚。 |
transports |
僅用于sioconnector,配置socket.io的通信方式差油,可選websocket拗军、xhr-polling等任洞。 |
會(huì)話配置sessionConfig
配置 |
描述 |
singleSession |
是否開啟單個(gè)用戶綁定單個(gè)會(huì)話,設(shè)置為true則禁止用戶同時(shí)綁定多個(gè)會(huì)話发侵。 |
pushSchedulerConfig
配置 |
描述 |
scheduler |
scheduler組件具體調(diào)度策略配置交掏,默認(rèn)直接將響應(yīng)發(fā)送給客戶端。pomelo提供帶緩沖帶定時(shí)的調(diào)度策略刃鳄。 |
flushInterval |
刷新間隔毫秒時(shí)間盅弛,默認(rèn)20毫秒。 |
代理配置proxyConfig
配置 |
描述 |
cacheMsg |
是否開啟對(duì)RPC消息的緩沖 |
interval |
設(shè)置刷新緩存的周期 |
mailBoxFactory |
自定義mailbox工廠函數(shù) |
remoteConfig
配置 |
描述 |
cacheMsg |
是否緩存RPC消息 |
interval |
設(shè)置緩存刷新時(shí)間周期 |
acceptorFactory |
自定義acceptor工廠函數(shù) |
字典配置dictionaryConfig
配置 |
描述 |
dict |
客戶端路由字符串文件的位置叔锐,默認(rèn)使用config/dictionary.json挪鹏。 |
頻道配置 channelConfig
配置 |
描述 |
broadcastFilter |
配置廣播的過濾函數(shù),會(huì)在執(zhí)行channel.broadcast時(shí)在前端服務(wù)器上愉烙,消息發(fā)送前為每個(gè)session進(jìn)行過濾讨盒。 |