Entry point of a micro-service application
up vote
0
down vote
favorite
This is the main entry point for the my application (a micro-service). I feel like I'm doing a lot of things outside of main()
, but even if I brought them all inside of main()
, that would just make that massive.
Still relatively new to writing production ready code, and whilst there are no problems with this code, i can't help but feel there are better ways to structure it? Is there a better way of breaking down the code I have already written and making the code more readable/maintainable?
'use strict';
const fs = require('fs');
const http = require('http');
const {Receiver, Publisher} = require('openimprabbit');
const OSSEventEmitter = require('oss-events-emitter');
const Discovery = require('service-discovery');
const authorisation = require('./services/Authorisation');
const jobParser = require('./Parser');
const rabbitMQURL = new URL('amqp://'+process.env.AMQP_HOST);
rabbitMQURL.port = process.env.AMQP_PORT;
rabbitMQURL.username = process.env.AMQP_USER;
rabbitMQURL.password = process.env.AMQP_PASS;
const rabbitMQDetails = {
url: rabbitMQURL.toString(),
exchange: process.env.AMQP_SEND_EXCHANGE,
exchangeType: process.env.AMQP_TOPIC,
routingKey: '',
};
const ossEmitter = new OSSEventEmitter(rabbitMQDetails);
const Logger = require('./AOP/Logger');
Logger.Publisher(ossEmitter);
const QAFlagValidator = Logger.ClassHandler(
require('./job/QAFlagValidator')
);
const SchemaValidator = Logger.ClassHandler(
require('./job/validation/SchemaValidator')
);
const RuleSetCheck = Logger.ClassHandler(
require('./job/validation/RuleSetCheck')
);
const Releases = Logger.ClassHandler(require('./services/Releases'));
const discovery = new Discovery(http, process.env.DISCOVERY_URL);
const receiver = new Receiver(
rabbitMQURL.toString(),
process.env.AMQP_EXCHANGE,
process.env.AMQP_TOPIC,
process.env.AMQP_QUEUE,
process.env.AMQP_PATTERN,
{noAck: true}
);
const releaseAPI = new Releases(authorisation, http, discovery);
const schemaValidator = new SchemaValidator(
fs,
[
{location: './schemas/asset-controller.json', key: 'asset_controller'},
{location: './schemas/label.json', key: 'label'},
{location: './schemas/musicset.json', key: 'musicset'},
{location: './schemas/artist.json', key: 'artist'},
]
);
const rulesCheck = new RuleSetCheck(fs, Logger);
const qaValidator = new QAFlagValidator(
schemaValidator, rulesCheck
);
const main = async () => {
receiver.listen( async (msg) => {
const releaseIDs = jobParser.parse(msg);
const releases = await releaseAPI.getReleases(releaseIDs)
.catch((err) => {
console.error(err);
});
releases.forEach((release) => {
if (Object.keys(release).length) {
const rules = qaValidator.startValidation(release);
// console.log(rules);
}
});
});
};
main()
.catch((err) => {
console.error(err);
});
javascript object-oriented node.js
add a comment |
up vote
0
down vote
favorite
This is the main entry point for the my application (a micro-service). I feel like I'm doing a lot of things outside of main()
, but even if I brought them all inside of main()
, that would just make that massive.
Still relatively new to writing production ready code, and whilst there are no problems with this code, i can't help but feel there are better ways to structure it? Is there a better way of breaking down the code I have already written and making the code more readable/maintainable?
'use strict';
const fs = require('fs');
const http = require('http');
const {Receiver, Publisher} = require('openimprabbit');
const OSSEventEmitter = require('oss-events-emitter');
const Discovery = require('service-discovery');
const authorisation = require('./services/Authorisation');
const jobParser = require('./Parser');
const rabbitMQURL = new URL('amqp://'+process.env.AMQP_HOST);
rabbitMQURL.port = process.env.AMQP_PORT;
rabbitMQURL.username = process.env.AMQP_USER;
rabbitMQURL.password = process.env.AMQP_PASS;
const rabbitMQDetails = {
url: rabbitMQURL.toString(),
exchange: process.env.AMQP_SEND_EXCHANGE,
exchangeType: process.env.AMQP_TOPIC,
routingKey: '',
};
const ossEmitter = new OSSEventEmitter(rabbitMQDetails);
const Logger = require('./AOP/Logger');
Logger.Publisher(ossEmitter);
const QAFlagValidator = Logger.ClassHandler(
require('./job/QAFlagValidator')
);
const SchemaValidator = Logger.ClassHandler(
require('./job/validation/SchemaValidator')
);
const RuleSetCheck = Logger.ClassHandler(
require('./job/validation/RuleSetCheck')
);
const Releases = Logger.ClassHandler(require('./services/Releases'));
const discovery = new Discovery(http, process.env.DISCOVERY_URL);
const receiver = new Receiver(
rabbitMQURL.toString(),
process.env.AMQP_EXCHANGE,
process.env.AMQP_TOPIC,
process.env.AMQP_QUEUE,
process.env.AMQP_PATTERN,
{noAck: true}
);
const releaseAPI = new Releases(authorisation, http, discovery);
const schemaValidator = new SchemaValidator(
fs,
[
{location: './schemas/asset-controller.json', key: 'asset_controller'},
{location: './schemas/label.json', key: 'label'},
{location: './schemas/musicset.json', key: 'musicset'},
{location: './schemas/artist.json', key: 'artist'},
]
);
const rulesCheck = new RuleSetCheck(fs, Logger);
const qaValidator = new QAFlagValidator(
schemaValidator, rulesCheck
);
const main = async () => {
receiver.listen( async (msg) => {
const releaseIDs = jobParser.parse(msg);
const releases = await releaseAPI.getReleases(releaseIDs)
.catch((err) => {
console.error(err);
});
releases.forEach((release) => {
if (Object.keys(release).length) {
const rules = qaValidator.startValidation(release);
// console.log(rules);
}
});
});
};
main()
.catch((err) => {
console.error(err);
});
javascript object-oriented node.js
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is the main entry point for the my application (a micro-service). I feel like I'm doing a lot of things outside of main()
, but even if I brought them all inside of main()
, that would just make that massive.
Still relatively new to writing production ready code, and whilst there are no problems with this code, i can't help but feel there are better ways to structure it? Is there a better way of breaking down the code I have already written and making the code more readable/maintainable?
'use strict';
const fs = require('fs');
const http = require('http');
const {Receiver, Publisher} = require('openimprabbit');
const OSSEventEmitter = require('oss-events-emitter');
const Discovery = require('service-discovery');
const authorisation = require('./services/Authorisation');
const jobParser = require('./Parser');
const rabbitMQURL = new URL('amqp://'+process.env.AMQP_HOST);
rabbitMQURL.port = process.env.AMQP_PORT;
rabbitMQURL.username = process.env.AMQP_USER;
rabbitMQURL.password = process.env.AMQP_PASS;
const rabbitMQDetails = {
url: rabbitMQURL.toString(),
exchange: process.env.AMQP_SEND_EXCHANGE,
exchangeType: process.env.AMQP_TOPIC,
routingKey: '',
};
const ossEmitter = new OSSEventEmitter(rabbitMQDetails);
const Logger = require('./AOP/Logger');
Logger.Publisher(ossEmitter);
const QAFlagValidator = Logger.ClassHandler(
require('./job/QAFlagValidator')
);
const SchemaValidator = Logger.ClassHandler(
require('./job/validation/SchemaValidator')
);
const RuleSetCheck = Logger.ClassHandler(
require('./job/validation/RuleSetCheck')
);
const Releases = Logger.ClassHandler(require('./services/Releases'));
const discovery = new Discovery(http, process.env.DISCOVERY_URL);
const receiver = new Receiver(
rabbitMQURL.toString(),
process.env.AMQP_EXCHANGE,
process.env.AMQP_TOPIC,
process.env.AMQP_QUEUE,
process.env.AMQP_PATTERN,
{noAck: true}
);
const releaseAPI = new Releases(authorisation, http, discovery);
const schemaValidator = new SchemaValidator(
fs,
[
{location: './schemas/asset-controller.json', key: 'asset_controller'},
{location: './schemas/label.json', key: 'label'},
{location: './schemas/musicset.json', key: 'musicset'},
{location: './schemas/artist.json', key: 'artist'},
]
);
const rulesCheck = new RuleSetCheck(fs, Logger);
const qaValidator = new QAFlagValidator(
schemaValidator, rulesCheck
);
const main = async () => {
receiver.listen( async (msg) => {
const releaseIDs = jobParser.parse(msg);
const releases = await releaseAPI.getReleases(releaseIDs)
.catch((err) => {
console.error(err);
});
releases.forEach((release) => {
if (Object.keys(release).length) {
const rules = qaValidator.startValidation(release);
// console.log(rules);
}
});
});
};
main()
.catch((err) => {
console.error(err);
});
javascript object-oriented node.js
This is the main entry point for the my application (a micro-service). I feel like I'm doing a lot of things outside of main()
, but even if I brought them all inside of main()
, that would just make that massive.
Still relatively new to writing production ready code, and whilst there are no problems with this code, i can't help but feel there are better ways to structure it? Is there a better way of breaking down the code I have already written and making the code more readable/maintainable?
'use strict';
const fs = require('fs');
const http = require('http');
const {Receiver, Publisher} = require('openimprabbit');
const OSSEventEmitter = require('oss-events-emitter');
const Discovery = require('service-discovery');
const authorisation = require('./services/Authorisation');
const jobParser = require('./Parser');
const rabbitMQURL = new URL('amqp://'+process.env.AMQP_HOST);
rabbitMQURL.port = process.env.AMQP_PORT;
rabbitMQURL.username = process.env.AMQP_USER;
rabbitMQURL.password = process.env.AMQP_PASS;
const rabbitMQDetails = {
url: rabbitMQURL.toString(),
exchange: process.env.AMQP_SEND_EXCHANGE,
exchangeType: process.env.AMQP_TOPIC,
routingKey: '',
};
const ossEmitter = new OSSEventEmitter(rabbitMQDetails);
const Logger = require('./AOP/Logger');
Logger.Publisher(ossEmitter);
const QAFlagValidator = Logger.ClassHandler(
require('./job/QAFlagValidator')
);
const SchemaValidator = Logger.ClassHandler(
require('./job/validation/SchemaValidator')
);
const RuleSetCheck = Logger.ClassHandler(
require('./job/validation/RuleSetCheck')
);
const Releases = Logger.ClassHandler(require('./services/Releases'));
const discovery = new Discovery(http, process.env.DISCOVERY_URL);
const receiver = new Receiver(
rabbitMQURL.toString(),
process.env.AMQP_EXCHANGE,
process.env.AMQP_TOPIC,
process.env.AMQP_QUEUE,
process.env.AMQP_PATTERN,
{noAck: true}
);
const releaseAPI = new Releases(authorisation, http, discovery);
const schemaValidator = new SchemaValidator(
fs,
[
{location: './schemas/asset-controller.json', key: 'asset_controller'},
{location: './schemas/label.json', key: 'label'},
{location: './schemas/musicset.json', key: 'musicset'},
{location: './schemas/artist.json', key: 'artist'},
]
);
const rulesCheck = new RuleSetCheck(fs, Logger);
const qaValidator = new QAFlagValidator(
schemaValidator, rulesCheck
);
const main = async () => {
receiver.listen( async (msg) => {
const releaseIDs = jobParser.parse(msg);
const releases = await releaseAPI.getReleases(releaseIDs)
.catch((err) => {
console.error(err);
});
releases.forEach((release) => {
if (Object.keys(release).length) {
const rules = qaValidator.startValidation(release);
// console.log(rules);
}
});
});
};
main()
.catch((err) => {
console.error(err);
});
javascript object-oriented node.js
javascript object-oriented node.js
edited Nov 14 at 17:13
200_success
127k15148410
127k15148410
asked Nov 14 at 15:20
Jarede
199116
199116
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207661%2fentry-point-of-a-micro-service-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown