-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (31 loc) · 1.13 KB
/
server.js
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
// load required packages
const logger = require("elogger");
const grpc = require("@grpc/grpc-js");
const protoLoader = require("@grpc/proto-loader");
const handlerObj = require("./handler");
// load article.proto to load the gRPC data contract
const packageDefinition = protoLoader.loadSync("./article.proto", {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
const articleManagerProto = grpc.loadPackageDefinition(packageDefinition).ArticleManagerPackage;
// initialize server and register handlers for the respective RPC methods
const server = new grpc.Server();
server.addService(articleManagerProto.ArticleService.service, {
createBulkEntries: handlerObj.createBulkEntries,
streamEntries: handlerObj.streamEntries
});
// bind & start the server process to port: 9111
const bindEndpoint = `0.0.0.0:9111`;
server.bindAsync(bindEndpoint, grpc.ServerCredentials.createInsecure(), (err, response) => {
if(err) {
logger.error(err);
}
else {
server.start();
logger.info(`Article manager gRPC service started on grpc://${bindEndpoint}`);
}
});