2023-07-13 18:06:07 +02:00
|
|
|
import { readFileSync } from 'fs';
|
2023-07-03 15:33:39 +02:00
|
|
|
import { MessageBroker } from '../build/esm/index.js';
|
2023-07-13 18:06:07 +02:00
|
|
|
const credentials = JSON.parse(readFileSync('../brokerCreds.json', { encoding: 'utf-8' }));
|
2023-07-03 15:33:39 +02:00
|
|
|
|
|
|
|
const broker = new MessageBroker({
|
2024-10-08 23:03:42 +02:00
|
|
|
createLogger: () =>
|
2023-07-03 15:33:39 +02:00
|
|
|
{
|
|
|
|
return {
|
2024-10-08 23:03:42 +02:00
|
|
|
debug: console.log,
|
|
|
|
info: console.log,
|
2023-07-03 15:33:39 +02:00
|
|
|
status: console.log,
|
2024-10-08 23:03:42 +02:00
|
|
|
warn: console.log,
|
|
|
|
error: console.error
|
2023-07-03 15:33:39 +02:00
|
|
|
};
|
|
|
|
}
|
2023-07-13 18:06:07 +02:00
|
|
|
}, credentials);
|
2023-07-03 15:33:39 +02:00
|
|
|
|
|
|
|
await broker.init();
|
2024-10-08 23:03:42 +02:00
|
|
|
broker.subscribe('db_cluster_status', (message) =>
|
2023-07-03 15:33:39 +02:00
|
|
|
{
|
2023-07-13 18:06:07 +02:00
|
|
|
if (message instanceof Buffer)
|
|
|
|
console.log(message.toString());
|
|
|
|
else
|
|
|
|
console.log(message);
|
2023-07-03 15:33:39 +02:00
|
|
|
});
|