Git Product home page Git Product logo

dorusu-js's Introduction

Dorusu-js - gRPC for Node.js in javascript

Build Status Code Coverage

This is not an official Google project.

The official Google-maintained implementation of gRPC for node.js is available at grpc-nodejs. Note that Google only maintains one offical implementation of gRPC in any programming language - all the official support for nodejs is focused on grpc-nodejs.

This is an alternate implementation written in javascript by a Googler. It

  • interoperates successfully with the official gRPC implementations, i.e it implements the gRPC spec and passes all the core gRPC interop tests

  • has an incompatible API surface to grpc-nodejs, for reasons explained in the DESIGN SUMMARY.

    • There is a meta issue that triages other issues that will explain the differences via code snippets.

    • This meta issue will also be used to triage the impact that not being able use dorusu-js as a drop-in replacement for grpc-nodejs has on users.

DESIGN SUMMARY

dorusu-js provides strongly-idiomatic client and server implementations supporting the gRPC rpc protocol.

The main governing power behind the dorusu API design is that it provides elements similar to the existing node.js HTTP2 API, node-http2, which is in turn very similar to the node HTTP API/HTTPS API.

In part, the similarity comes from direct use of classes defined in node-http2. In other cases the classes have been extended to enforce additional restrictions the RPC Protocol places on the use HTTP2.

The goal of the design is that

  • the client rpc api surface has a strong similarity to the builtin node.js https library surface
  • the server rpc api surface has a strong similarity to the Express API

The result should be an rpc client and server with an intuitive surface that is easy to learn due to its similarity to existing node.js code. I.e, most of the API should already be familiar to developers, and important new rpc features like streaming requests and responses are available as minor deltas that are easily understood.

Missing Features

At this point in time, dorusu-js is missing features that grpc-nodejs provides, e.g,

There are also other features that are planned for grpc-nodejs that dorusu-js should implement:

These missing features are tracked with issues and triaged via single meta tracking issue

EXAMPLES

Given the greeter protobuf IDL: helloworld.proto

syntax = "proto3";

option java_package = "ex.grpc";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

Serve greetings with a server: helloworld_server.js

var protobuf = require('dorusu/protobuf');
var server = require('dorusu/server');

/**
 * Implements the SayHello RPC method.
 */
function sayHello(request, response) {
  request.on('data', function(msg) {
    response.write({message: 'Hello ' + msg.name});
  });
  request.on('end', function() {
    response.end();
  });
  request.on('error', function() {
    response.end();
  });
};

/**
 * Starts an RPC server that receives requests for the Greeter service at the
 * sample server port
 */
function main() {
  var hellopb = protobuf.requireProto('./helloworld', require);
  var app = hellopb.helloworld.Greeter.serverApp;
  app.register('/helloworld/SayHello', sayHello);

  /* server.raw.CreateServer is insecure, server.createServer is alway secure */
  s = server.raw.createServer({
    app: app,
    host: '0.0.0.0'
  });
  s.listen(50051);
}

main();

Access greetings with a client: helloworld_client.js

var protobuf = require('dorusu/protobuf');

function main() {
  var hellopb = protobuf.requireProto('./helloworld', require);
  /* <package>.Client.raw is insecure, <package>.Client is alway secure */
  var GreeterClient = hellopb.helloworld.Greeter.Client.raw;
  var client = new GreeterClient({
    host: 'localhost',
    port: 50051,
    protocol: 'http:'
  });

  var user = process.argv[2] || 'world';
  // Call the say hello method remotely.
  client.sayHello({name: user}, function (resp) {
    resp.on('data', function(pb) {
      console.log('Greeting:', pb.message);
    });
  });
}

main();

Try it out

node helloworld_server.js &
node helloworld_client.js
node helloworld_client.js dorusu

Other examples

You can also try out the large math_server and math_client examples in this repo

npm update  # install dorusu locally
example/math_server.js &

# (same directory, another terminal window)
example/math_client.js

Try it out with much nicer log output by installing bunyan

npm install -g bunyan # installs bunyan, may require sudo depending on how node is set up

# (from this directory)
HTTP2_LOG=info example/math_server.js | bunyan -o short &

# (same directory, another terminal)
example/math_client.js
HTTP2_LOG=info example/math_client.js | bunyan -o short

TESTING

unit tests

npm test

interop tests

Note The node interop test client is tested against the node interop test server as part of the unit tests. interop-test here actual runs against grpc-go.

  • the test is skipped unless Go is installed.
  • when Go is available, the test installs grpc-go to a temporary location and runs the interop client against the grpc-go server and vice versa.
# Install the Go interop test server and client to a temporary location
npm run install-go-interop

# Run the interop tests
npm run interop-test

production interop tests

npm run prod-interop
  • without bunyan installed (the logs are nicely formatted)
npm run bunyan-prod-interop

CONTRIBUTING/REPORTING ISSUES

Contributions to this library are always welcome and highly encouraged. See the CONTRIBUTING documentation for more information on how to get started.

dorusu-js's People

Contributors

jmuk avatar mortonfox avatar tbetbetbe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dorusu-js's Issues

How to keep track of features in grpc nodejs that are not implemented yet

The latest version (0.4.0) of dorusu-js is missing features that grpc-nodejs provides.

This is a meta issue that describes how to keep track of the missing features

Tracking missing features

For each missing feature

  • there should be an issue tagged with label 'implementation gap'
  • the issue's initial comment should simply describe the missing feature, follow-up comments should propose the implementation.
  • the issue should mention this meta issue, so by looking at the mentions of this issue it's possible to see the state of the all the missing features
  • if the description has enough detail, the initial comment should just mention this issue

Add a changelog

  • it's useful
  • it's also referred to already in CONTRIBUTING.md

Production usage?

Hi,

I am wondering if anyone is using this library is used in production.

Is 'connection' an allowed response header ?

#29 adds an extension to the IncomingResponse._validateHeaders, as Google servers return 'connection' as a header in some responses, and node-http2 sees that a protocol violation.

Determine what's right, and if node-http2 needs updating, raise an issue there.

Fix the random test flakes when test server is not ready

Sometimes the test 'headers special: timeout headers should succeed in sending a good grpc-timeout value' fails with the following error. Let's re-write that test to stop this from happening.

  1. Base RPC Client insecure: headers special: timeout headers should succeed in sending a good grpc-timeout value:
    Uncaught Error: connect ECONNREFUSED 127.0.0.1:41009
    at Object.exports._errnoException (util.js:856:11)
    at exports._exceptionWithHostPort (util.js:879:20)
    at TCPConnectWrap.afterConnect as oncomplete

Coverage is low: add more unit tests

Coverage is < 90%

  • ideally it should be 100%,
  • above 95% is OK

This issue can be closed one coverage reaches 95%, and it should re-opened if any change causes it drop below that.

How to keep track of differences with grpc nodejs surface

dorusu-js has an incompatible API surface to grpc-nodejs, for reasons explained in the DESIGN SUMMARY

This is a meta issue explaining how issues will be used to describe the surface differences, and when and how the 'surface difference' label should be used

Tracking surface differences

  • for each surface difference
    • there should be an issue tagged with label 'surface difference'
    • the issue's initial comment will include
      • a snippet of dorusu-js code
      • the equivalent in grpc-nodejs code
      • where applicable, the equivalent in non-rpc code

Triaging customer issues caused by surface differences

  • any reported customer issue that is determined to be caused by a surface difference
    • will be labelled 'surface difference'
    • will be labelled 'bug'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.