layotto
v1.17.0
Published
Layotto Node.js SDK
Downloads
24
Readme
Layotto Node.js SDK
The Layotto Node.js SDK to build your application.
Clone
git clone --recurse-submodules [email protected]:layotto/js-sdk.git
If forgot to add --recurse-submodules
, you can run git submodule update --init --recursive
to clone the submodules.
More git submodule commands, please refer to Git submodule.
Usage
State
demo/state.ts
import { Client } from 'layotto';
const storeName = 'redis';
const key = 'foo-js-sdk';
const value = `bar, from js-sdk, ${Date()}`;
await client.state.save({
storeName,
states: { key, value },
});
console.log('saveState success, key: %j, value: %j', key, value);
const resValue = await client.state.get({ storeName, key });
console.log('getState success, key: %j, value: %j, toString: %j',
key, resValue, Buffer.from(resValue).toString('utf8'));
Development
Install dependencies
npm install
Generate gRPC files
Should install grpc-tools first. MacOS M1 follow this issue.
npm run build:grpc
Run Tests
step 1. Set up the environment
- Running redis and etcd under Docker
docker-compose up -d
- Start a echoserver for testing the rpc api
node demo/rpc/http/server.js
If you want to know more about this, check https://mosn.io/layotto/#/zh/start/rpc/helloworld
- Start Layotto, see How to run layotto
cd layotto/cmd/layotto
go build
./layotto start -c ../../../demo/config.json
step 2: Run the tests
- Then, run the test script by npm
npm run test:unit
Enable trace debug log for grpc-js:
GRPC_TRACE=compression GRPC_VERBOSITY=debug GRPC_TRACE=all npm run test test/unit/client/Invoker.test.ts
Reference
- Core concepts, architecture and lifecycle
- Get Start with gRPC on Node.js
- Node.js gRPC Library
- Understanding Streams in Node.js
- Go Proxy in China
- How to build a bi-directional streaming gRPC service with Node.js and Java
License
Contributors
|fengmk2|seeflood|LZHK1ng|killagu| | :---: | :---: | :---: | :---: |
This project follows the git-contributor spec, auto updated at Thu Oct 13 2022 15:14:41 GMT+0800
.