1.7.7 • Published 4 years ago

comm-interface v1.7.7

Weekly downloads
76
License
ISC
Repository
github
Last release
4 years ago

Comm Interface

Provides simple calls for GRPC and Kube API communication. This module uses grpc-promise and kubernetes-client modules as main dependencies.

Installation

npm install comm-interface

GRPC Example

Client (Unary request)

import { GrpcClient } from 'comm-interface';

const address = '0.0.0.0:8080';
const modelPath = 'test.proto';
const serviceName = 'MessageService';
const packageName = 'package';
const debugMode = false;
const protoOpts = {
  keepCase: false,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
};
const message = {
  message: "Hello World!"
};

async function main() {
  const grpcClient = new GrpcClient(address, modelPath, serviceName, packageName, debugMode, protoOpts);

  const methodName = 'sendMessage()'; //defined in service: serviceName
  const response = await grpcClient.publishUnary(message, methodName);
  console.log(response);
}

main();

Server (Unary request)

import { GrpcServer } from 'comm-interface';

const address = '0.0.0.0:8080';
const modelPath = 'test.proto';
const serviceName = 'MessageService';
const packageName = 'package';
const debugMode = false;
const protoOpts = {
  keepCase: false,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
};

function sendMessage(call: any, callback: any) {
  callback(null, call.request);
}

async function main() {
  const grpcServer = new GrpcServer(address, modelPath, serviceName, packageName, { sendMessage }, debugMode, protoOpts);
  grpcServer.start();
}

main();

Kube API Watch Example

import { KubeApi } from 'comm-interface';

const path = '/api/v1/namespaces';

function kubeWatchCallback(type: string, obj: any) {
  if (type === 'ADDED') console.log('new object:');
  else if (type === 'MODIFIED') console.log('changed object:');
  else if (type === 'DELETED') console.log('deleted object:');
  else console.log('unknown type: ' + type);
  console.log(obj);
}

function kubeWatchErrorCallback(err: any) {
  throw new Error(err);
}

function main() {
  const kubeApi = new KubeApi(); // empty options load from default kube options
  kubeApi.watchRequest(path, kubeWatchCallback, kubeWatchErrorCallback);
}

main();
1.7.7

4 years ago

1.7.65

4 years ago

1.7.63

4 years ago

1.7.64

4 years ago

1.7.62

4 years ago

1.7.61

4 years ago

1.7.6

4 years ago

1.7.5

4 years ago

1.7.4

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.6.994

4 years ago

1.7.0

4 years ago

1.6.993

4 years ago

1.6.992

4 years ago

1.6.991

4 years ago

1.6.99

4 years ago

1.6.97

4 years ago

1.6.98

4 years ago

1.6.96

4 years ago

1.6.95

4 years ago

1.6.94

4 years ago

1.6.93

4 years ago

1.6.91

4 years ago

1.6.92

4 years ago

1.6.9

4 years ago

1.6.8

4 years ago

1.6.7

4 years ago

1.6.6

4 years ago

1.6.5

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

5 years ago

1.5.8

5 years ago

1.5.7

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.9

5 years ago

1.4.8

5 years ago

1.4.7

5 years ago

1.4.6

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago