2023-07-13 18:06:07 +02:00
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 ( {
2024-10-08 23:03:42 +02:00
createLogger : ( ) =>
2023-07-13 18:06:07 +02:00
{
return {
2024-10-08 23:03:42 +02:00
debug : console . log ,
info : console . log ,
2023-07-13 18:06:07 +02:00
status : console . log ,
2024-10-08 23:03:42 +02:00
warn : console . log ,
error : console . error
2023-07-13 18:06:07 +02:00
} ;
}
} , {
2024-10-08 23:03:42 +02:00
load : true ,
2023-07-13 18:06:07 +02:00
credentials ,
cluster : {
2024-10-08 23:03:42 +02:00
canRetry : true ,
2023-07-13 18:06:07 +02:00
removeNodeErrorCount : 5 ,
2024-10-08 23:03:42 +02:00
restoreNodeTimeout : 60000 ,
defaultSelector : 'RR'
2023-07-13 18:06:07 +02:00
}
} ) ;
const broker = new MessageBroker ( {
2024-10-08 23:03:42 +02:00
createLogger : ( ) =>
2023-07-13 18:06:07 +02:00
{
return {
2024-10-08 23:03:42 +02:00
debug : console . log ,
info : console . log ,
2023-07-13 18:06:07 +02:00
status : console . log ,
2024-10-08 23:03:42 +02:00
warn : console . log ,
error : console . error
2023-07-13 18:06:07 +02:00
} ;
}
} , {
2024-10-08 23:03:42 +02:00
load : true ,
host : 'rabbitmq-01.stylis.local' ,
user : 'stylis' ,
pass : 'RrwJyrfeXFMimDH3hjZ5xSreMAmXtQJj' ,
2023-07-13 18:06:07 +02:00
vhost : 'development' ,
2024-10-08 23:03:42 +02:00
port : 5672
2023-07-13 18:06:07 +02:00
} ) ;
await broker . init ( ) ;
await maria . init ( ) ;
broker . subscribe ( 'db_cluster_status' , maria . statusUpdateListener ) ;
2024-10-08 23:03:42 +02:00
setInterval ( async ( ) =>
2023-07-13 18:06:07 +02:00
{
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 ( ) ;
2024-10-08 23:03:42 +02:00
process . on ( 'SIGINT' , async ( ) =>
2023-07-13 18:06:07 +02:00
{
await broker . close ( ) ;
await maria . close ( ) ;
process . exit ( ) ;
} ) ;