This repository was archived by the owner on Jul 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (38 loc) · 1.21 KB
/
Copy pathindex.js
File metadata and controls
45 lines (38 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const Bottle = require('bottlejs');
const yaml = require('js-yaml');
const fs = require('fs');
const { validate, AMQP_SCHEMA } = require('./validators');
const AmqpConnection = require('./lib/amqp/amqpConnection');
const createLogger = require('./logger');
class ContainerApp {
/**
* @constructor
* @param {String} filename rabbitmq yaml file definition
*/
constructor(filename) {
this.filename = filename;
this.dependencyInjector = new Bottle();
}
async bootstrapAmqpApp() {
const amqpYamlSchema = yaml.safeLoad(fs.readFileSync(this.filename, 'utf8'));
const amqpJsonSchema = await validate(amqpYamlSchema, AMQP_SCHEMA);
const {
name: loggerName = 'amqp_logger',
filepath = '/etc/logs'
} = amqpJsonSchema['logger'] ? amqpJsonSchema['logger'] : {};
const amqpLogger = new createLogger(loggerName, {
path: filepath,
levels: ['debug'],
});
this.dependencyInjector.factory('amqp_logger', () => amqpLogger);
try {
await new AmqpConnection(amqpJsonSchema, this.dependencyInjector);
} catch(err) {
amqpLogger.error(err);
}
}
}
module.exports = (yamlFile) => {
const containerApp = new ContainerApp(yamlFile);
return containerApp;
};