1.0.2.alpha release
Framework extending gRPC-Node. Standardized syntax for transpiling protoBufs into Node.js, creating servers, clients, and managing gRPC channels in distributed systems.
gRPC-Node has a complex API but does not document or support all of the features available in gRPC-goLang or gRPC-Java. We standardize the syntax to expose all existing features and extend undersupported features in the Node.js ecosystem.
npm i --save firecomm
syntax = 'proto3';
package exampleAPI;
service FileTransfer {
rpc ClientToServer (stream File) returns (Confirmation) {};
rpc ServerToClient (Confirmation) returns (stream File) {}
}
service HeavyMath {
rpc UnaryExample (Math) returns (Math) {}
rpc BidiExample (stream Math) returns (stream Math) {}
}
message Confirmation {
bool status = 1;
string comments = 2;
}
message File {
bytes fileBuffer = 1;
}
message Math {
double num = 1;
}
const { build } = require( 'firecomm' );
const package = build( PROTO_PATH, CONFIG_OBJECT );
module.exports = package;
returns a gRPC package object with SERVICE_DEFINITION
s as properties
const { Server } = require( 'firecomm' );
const server = new Server();
returns a gRPC server instance object
4. Define your HANDLER_FUNCTION
for each RPC_METHOD
and/or MIDDLEWARE_STACK
functions for each RPC_METHOD
exampleUnaryHandler( CALL ) {
// single response
CALL.send({ response: value });
};
exampleClientStreamHandler( CALL ) {
// listeners for stream from client
CALL.on('data', request => someFunctionality(request));
// single response
CALL.send({ response: value });
};
exampleServerStreamHandler( CALL ) {
// some logic to warrant a streaming response
CALL.write({ responseChunk: value });
};
exampleDuplexHandler( CALL ) {
// listeners for stream from client
CALL.on('data', request => someFunctionality(request));
// some logic to warrant a streaming response
CALL.write({ responseChunk: value });
};
module.exports = {
exampleUnary,
exampleClientStream,
exampleServerStream,
exampleDuplex,
}
doesn't return anything
const { Server } = require( 'firecomm' );
const server = new Server();
server.addService( SERVICE, RPC_METHODS_OBJECT );
doesn't return anything
const { Server } = require( 'firecomm' );
const server = new Server();
server.addService( SERVICE, RPC_METHODS_OBJECT );
server.bind( SOCKETS, SECURITY_CONFIG_OBJECT );
doesn't return anything
const { Server } = require( 'firecomm' );
const server = new Server();
server.addService( SERVICE, RPC_METHODS_OBJECT );
server.bind( SOCKETS, SECURITY_CONFIG_OBJECT );
server.start();
doesn't return anything
const { Stub } = require( 'firecomm' );
const clientStub = new Stub(
SERVICE,
SOCKET,
SECURITY_CONFIG_OBJECT
);
returns a gRPC stub instance object
const { Stub } = require( 'firecomm' );
const clientStub = new Stub(
SERVICE,
SOCKET,
SECURITY_CONFIG_OBJECT
);
clientStub.exampleUnary( MESSAGE, CALLBACK );
const clientStream =
clientStub.exampleClientStream( MESSAGE );
// some logic to warrant a streaming response
clientStream.write( MESSAGE );
const serverStream =
clientStub.exampleServerStream( MESSAGE );
// listeners for stream from server
serverStream.on( 'data', response =>
someFunctionality(request));
const duplex =
clientStub.exampleDuplex( MESSAGE );
// listeners for stream from server
duplex.on( 'data', response =>
someFunctionality(request));
// some logic to warrant a streaming request
duplex.write( 'data', response =>
someFunctionality(request));
CLIENT_STREAM
, SERVER_STREAM
, and DUPLEX
return a stream object