Skip to content

Latest commit

 

History

History
169 lines (120 loc) · 4.76 KB

README.md

File metadata and controls

169 lines (120 loc) · 4.76 KB

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