wrappers/tests/testClusterStatus.js

63 lines
1.6 KiB
JavaScript

process.env.NODE_ENV = 'development';
import { MariaDB, MessageBroker } from '../build/esm/index.js';
import { readFileSync } from 'fs';
const credentials = JSON.parse(readFileSync('./credentials.json', { encoding: 'utf-8' }));
const maria = new MariaDB({
createLogger: () =>
{
return {
debug: console.log,
info: console.log,
status: console.log,
warn: console.log,
error: console.error
};
}
}, {
load: true,
credentials,
cluster: {
canRetry: true,
removeNodeErrorCount: 5,
restoreNodeTimeout: 60000,
defaultSelector: 'RR'
}
});
const broker = new MessageBroker({
createLogger: () =>
{
return {
debug: console.log,
info: console.log,
status: console.log,
warn: console.log,
error: console.error
};
}
}, {
load: true,
host: 'rabbitmq-01.stylis.local',
user: 'stylis',
pass: 'RrwJyrfeXFMimDH3hjZ5xSreMAmXtQJj',
vhost: 'development',
port: 5672
});
await broker.init();
await maria.init();
broker.subscribe('db_cluster_status', maria.statusUpdateListener);
setInterval(async () =>
{
console.log('Result: ', await maria.query('SHOW STATUS WHERE `Variable_name` = "wsrep_gcomm_uuid" OR `Variable_name` = "wsrep_local_state_comment"', { node: 'maria-t03', errorIfNodeUnavailable: true }).catch(() => null));
}, 15_000).unref();
process.on('SIGINT', async () =>
{
await broker.close();
await maria.close();
process.exit();
});