Giter Site home page Giter Site logo

examples's Introduction

Mali Examples

A repository containing small examples to illustrate the use of Mali for creating gRPC applications.

Installation

$ npm install

Examples

The stock gRPC Hello World example converted to use Mali for server. Both dynamic and static code generated examples are provided. With dynamic we create a server from protocol buffer definition file. With static we create the server from pre-generated Node.js code. The client is unchanged from the gRPC client sample code.

Run the server

$ # from this directory
$ node ./hello_world_dynamic/greeter_server.js
$ # OR
$ node ./hello_world_static/greeter_server.js

Run the client

$ # from this directory
$ node ./hello_world_dynamic/greeter_client.js
$ # OR
$ node ./hello_world_static/greeter_client.js

The stock gRPC Route Guide tutorial converted to use Mali for server with some notable changes:

  • We use the route_guide_db.json as the database source.
  • All data is asynchronously queried to the file using streaming to demonstrate asynchronous interaction with a "database".
  • Similarly Notes are written to route_guide_db_notes.json file to simulate asynchronous I/O interactions. This file is truncated at startup to get a clean slate.
  • Use of logger middleware.

The client is unchanged from the gRPC client sample code.

Run the server

$ # from within route_guide directory
$ node ./server.js

Run the client

$ # from this directory
$ node ./route_guide/route_guide_client.js --db_path=./route_guide/route_guide_db.json

A simple "User" service that demonstrates usage of apikey, logger and tojson middleware. As well since currently Protocol Buffers (and therefore gRPC) doesn't support serializing variable JSON data (the user "metadata" field in this case), this example shows how to serialize the property by converting it to bytes. This is not the most efficient solution but the best we can do right now.

Run the server

$ # from within user_service directory
$ node ./server.js

Run the tests for the service

$ # from this directory
$ npm run test-user

A simple service that asynchronously processes a stream of requests and collects the errors and returns the number of succeeded and the failed details.

Run the server

$ # from within secret_service directory
$ node ./server.js

Run the client

$ # from within secret_service directory
$ node ./client.js

gRPC can be used to implement a service that sends updates to all connected clients. This can be achieved using response stream calls. In this contrieved example clients open a stream response connection using syncWidgets call, which returns all "updated" widgets since some timestamp. Afterwards as widgets are updated the server sends the updates to all the connected clients. The server abstracts and mocks a simple widget store which can be either another service (ie widget service) or a database. Similarly it abstracts and mocks an update notification mechanism that notifies it of updated widgets (for example incoming messages from AMQP or some other messanging system).

Run the server

$ # from within examples directory
$ node ./push/server.js

Run the client

$ # from within examples directory
$ node ./push/client.js

Run an app that makes lots of concurrent client requests

$ # from within examples directory
$ node ./push/lotsofclients.js

Demonstrates different ways of comminicating erros to client. Read more.

Run the server

To run the traditional gRPC implementation:

$ # from within examples directory
$ node ./errors/grpc_server.js

Mali implementation:

$ # from within examples directory
$ node ./errors/mali_server.js

Run the client

Experiment with different calls to explore.

$ # from within examples directory
$ node ./errors/client.js

examples's People

Contributors

bojand avatar jeffhx avatar

Watchers

 avatar  avatar

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.