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()';
const response = await grpcClient.publishUnary(message, methodName);
console.log(response);
}
main();
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();
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();
kubeApi.watchRequest(path, kubeWatchCallback, kubeWatchErrorCallback);
}
main();