调整 app.ts 中的应用配置
This commit is contained in:
+71
-89
@@ -56,9 +56,9 @@ preload();
|
|||||||
* Init app for client.
|
* Init app for client.
|
||||||
*/
|
*/
|
||||||
let app = pinus.createApp();
|
let app = pinus.createApp();
|
||||||
app.set('name', 'chatofpomelo-websocket');
|
app.set('name', 'zyz');
|
||||||
|
|
||||||
// 加载数据库和redis
|
// 全局配置,对所有 env 所有 serverType 生效
|
||||||
app.configure(function () {
|
app.configure(function () {
|
||||||
app.loadConfig('database', app.getBase() + '/config/database');
|
app.loadConfig('database', app.getBase() + '/config/database');
|
||||||
app.loadConfig('serverName', app.getBase() + '/config/serverName');
|
app.loadConfig('serverName', app.getBase() + '/config/serverName');
|
||||||
@@ -66,30 +66,33 @@ app.configure(function () {
|
|||||||
console.log('db:', app.get('database'));
|
console.log('db:', app.get('database'));
|
||||||
console.log('serverName:', app.get('serverName'))
|
console.log('serverName:', app.get('serverName'))
|
||||||
|
|
||||||
mongoose.connect(app.get('database').mongo, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false }, (err) => {
|
initMongodb(app);
|
||||||
if (err) {
|
initRedis(app);
|
||||||
errlogger.error('mongodb connect err', err);
|
setupRoutes(app);
|
||||||
} else {
|
setupFilters(app);
|
||||||
console.log('mongodb connect suc');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const redisClient = connectRedis(app.get('database').redis, app.get('database').redispw);
|
app.set(RESERVED.ERROR_HANDLER, errorHandler);
|
||||||
app.set('redis', redisClient);
|
app.set(RESERVED.GLOBAL_ERROR_HANDLER, globalErrorHandler);
|
||||||
redLockService.initRedlock(redisClient);
|
// RPC 启用TCP协议
|
||||||
redlockCacheService.init();
|
app.set('proxyConfig', {
|
||||||
// TODO 重启 1 次只需要初始化 1 次,判断方法可以优化
|
mailboxFactory: createTcpMailBox,
|
||||||
if (app.serverId === 'master-server-1') {
|
// bufferMsg:true
|
||||||
redisService.readDataBase();
|
// rpc 超时时间
|
||||||
redisService.initAllRank();
|
// timeout: 20 * 1000,
|
||||||
redisService.clearComBtlQueue();
|
// dynamicUserProxy: true,
|
||||||
redisService.clearChannelServers();
|
});
|
||||||
updateTeamStatus(COM_TEAM_STATUS.DEFAULT, COM_TEAM_STATUS.LOOSE);
|
app.set('remoteConfig', {
|
||||||
updateTeamStatus(COM_TEAM_STATUS.FIGHTING, COM_TEAM_STATUS.LOOSE);
|
acceptorFactory: createTcpAcceptor,
|
||||||
}
|
// bufferMsg:true,
|
||||||
|
// interval:50,
|
||||||
|
});
|
||||||
|
app.set('serverConfig', {
|
||||||
|
'reloadHandlers': true,
|
||||||
|
'reloadRemotes': true,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// app configuration
|
// 对所有 env 的 个别 serverType 进行配置
|
||||||
app.configure(ALL_ENVS, 'connector', function () {
|
app.configure(ALL_ENVS, 'connector', function () {
|
||||||
app.set('connectorConfig',
|
app.set('connectorConfig',
|
||||||
{
|
{
|
||||||
@@ -99,14 +102,6 @@ app.configure(ALL_ENVS, 'connector', function () {
|
|||||||
useProtobuf: true
|
useProtobuf: true
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
// 缓存大小不够 日志示例
|
|
||||||
[2020-03-27T10:44:48.752] [ERROR] pinus - [chat-server-1 channelService.js] [pushMessage] fail to dispatch msg to serverId: connector-server-1, err:RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 0. Received 1
|
|
||||||
at boundsError (internal/buffer.js:53:9)
|
|
||||||
at writeU_Int8 (internal/buffer.js:562:5)
|
|
||||||
at Buffer.writeUInt8 (internal/buffer.js:569:10)
|
|
||||||
at Encoder.writeBytes (F:\develop\gong4-server\logicServer\pinus\packages\pinus-protobuf\lib\encoder.ts:195:20)
|
|
||||||
*/
|
|
||||||
app.set('protobufConfig', {
|
app.set('protobufConfig', {
|
||||||
// protobuf Encoder 使用 5m 的缓存 需要保证每个消息不会超过指定的缓存大小,超过了就会抛出异常
|
// protobuf Encoder 使用 5m 的缓存 需要保证每个消息不会超过指定的缓存大小,超过了就会抛出异常
|
||||||
encoderCacheSize: 5 * 1024 * 1024,
|
encoderCacheSize: 5 * 1024 * 1024,
|
||||||
@@ -124,28 +119,14 @@ app.configure(ALL_ENVS, 'gate', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.configure(ALL_ENVS, 'gm', function () {
|
app.configure(ALL_ENVS, 'gm', function () {
|
||||||
app.set('connectorConfig',
|
|
||||||
{
|
|
||||||
connector: pinus.connectors.hybridconnector,
|
|
||||||
useProtobuf: true
|
|
||||||
});
|
|
||||||
init();//将gm后台数据加载到gate服
|
init();//将gm后台数据加载到gate服
|
||||||
});
|
});
|
||||||
|
|
||||||
app.configure(ALL_ENVS, 'guild', function () {
|
app.configure(ALL_ENVS, 'guild', function () {
|
||||||
app.set('connectorConfig',
|
app.filter(guildAuthFilter(app));
|
||||||
{
|
})
|
||||||
connector: pinus.connectors.hybridconnector,
|
|
||||||
useProtobuf: true
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.configure(ALL_ENVS, 'systimer', function () {
|
app.configure(ALL_ENVS, 'systimer', function () {
|
||||||
app.set('connectorConfig',
|
|
||||||
{
|
|
||||||
connector: pinus.connectors.hybridconnector,
|
|
||||||
useProtobuf: true
|
|
||||||
});
|
|
||||||
timeTaskService.init();
|
timeTaskService.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -171,10 +152,47 @@ export function globalErrorHandler(err: Error, msg: any, resp: any,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// app configure
|
function initMongodb(app: _pinus.Application) {
|
||||||
app.configure(ALL_ENVS, function () {
|
mongoose.connect(app.get('database').mongo, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false }, (err) => {
|
||||||
app.set(RESERVED.ERROR_HANDLER, errorHandler);
|
if (err) {
|
||||||
app.set(RESERVED.GLOBAL_ERROR_HANDLER, globalErrorHandler);
|
errlogger.error('mongodb connect err', err);
|
||||||
|
} else {
|
||||||
|
console.log('mongodb connect suc');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function initRedis(app: _pinus.Application) {
|
||||||
|
const redisClient = connectRedis(app.get('database').redis, app.get('database').redispw);
|
||||||
|
app.set('redis', redisClient);
|
||||||
|
redLockService.initRedlock(redisClient);
|
||||||
|
redlockCacheService.init();
|
||||||
|
// TODO 重启 1 次只需要初始化 1 次,判断方法可以优化
|
||||||
|
if (app.serverId === 'master-server-1') {
|
||||||
|
redisService.readDataBase();
|
||||||
|
redisService.initAllRank();
|
||||||
|
redisService.clearComBtlQueue();
|
||||||
|
redisService.clearChannelServers();
|
||||||
|
updateTeamStatus(COM_TEAM_STATUS.DEFAULT, COM_TEAM_STATUS.LOOSE);
|
||||||
|
updateTeamStatus(COM_TEAM_STATUS.FIGHTING, COM_TEAM_STATUS.LOOSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupRoutes(app: _pinus.Application) {
|
||||||
|
app.route('chat', routeUtil.chat);
|
||||||
|
app.route('battle', routeUtil.battle);
|
||||||
|
app.route('gm', routeUtil.gm);
|
||||||
|
app.route('guild', routeUtil.guild);
|
||||||
|
app.route('activity', routeUtil.activity);
|
||||||
|
app.route('order', routeUtil.order);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupFilters(app: _pinus.Application) {
|
||||||
|
// filter configures
|
||||||
|
app.filter(new pinus.filters.time());
|
||||||
|
app.filter(new pinus.filters.timeout());
|
||||||
|
|
||||||
|
app.filter(globalFilter(app));
|
||||||
app.globalAfter((err: Error, routeRecord: RouteRecord, msg: any, session: FrontendOrBackendSession, resp: any, cb: HandlerCallback) => {
|
app.globalAfter((err: Error, routeRecord: RouteRecord, msg: any, session: FrontendOrBackendSession, resp: any, cb: HandlerCallback) => {
|
||||||
infologger.debug('global after ', msg && msg.route, msg && JSON.stringify(msg.body), session && session.get('roleId'));
|
infologger.debug('global after ', msg && msg.route, msg && JSON.stringify(msg.body), session && session.get('roleId'));
|
||||||
if (err) infologger.debug(err);
|
if (err) infologger.debug(err);
|
||||||
@@ -189,46 +207,10 @@ app.configure(ALL_ENVS, function () {
|
|||||||
}
|
}
|
||||||
cb(null);
|
cb(null);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// route configures
|
|
||||||
app.route('chat', routeUtil.chat);
|
|
||||||
app.route('battle', routeUtil.battle);
|
|
||||||
app.route('gm', routeUtil.gm);
|
|
||||||
app.route('guild', routeUtil.guild);
|
|
||||||
app.route('activity', routeUtil.activity);
|
|
||||||
app.route('order', routeUtil.order);
|
|
||||||
|
|
||||||
// filter configures
|
|
||||||
app.filter(new pinus.filters.time());
|
|
||||||
app.filter(new pinus.filters.timeout());
|
|
||||||
|
|
||||||
app.filter(globalFilter(app));
|
|
||||||
|
|
||||||
// RPC 启用TCP协议
|
|
||||||
app.set('proxyConfig', {
|
|
||||||
mailboxFactory: createTcpMailBox,
|
|
||||||
// bufferMsg:true
|
|
||||||
// rpc 超时时间
|
|
||||||
// timeout: 20 * 1000,
|
|
||||||
// dynamicUserProxy: true,
|
|
||||||
});
|
|
||||||
app.set('remoteConfig', {
|
|
||||||
acceptorFactory: createTcpAcceptor,
|
|
||||||
// bufferMsg:true,
|
|
||||||
// interval:50,
|
|
||||||
});
|
|
||||||
app.set('serverConfig', {
|
|
||||||
'reloadHandlers': true,
|
|
||||||
'reloadRemotes': true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.configure(ALL_ENVS, 'guild', function () {
|
|
||||||
app.filter(guildAuthFilter(app));
|
|
||||||
})
|
|
||||||
|
|
||||||
// TODO: 所有环境打开监听模块和日志
|
// TODO: 所有环境打开监听模块和日志
|
||||||
app.configure(ALL_ENVS, function () {
|
app.configure(function () {
|
||||||
// enable the system monitor modules
|
// enable the system monitor modules
|
||||||
app.enable('systemMonitor');
|
app.enable('systemMonitor');
|
||||||
app.enable('rpcDebugLog');
|
app.enable('rpcDebugLog');
|
||||||
|
|||||||
Reference in New Issue
Block a user