Created
September 11, 2016 11:09
-
-
Save andrewconnell/2aef31cc4bcdecaac259ef282f8eee74 to your computer and use it in GitHub Desktop.
Creating client to talk to the gRPC server RateKeeper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from 'path'; | |
let grpc: any = require('grpc'); | |
import { | |
IPublicCloudMeter, IProtobufTimestamp, IRateKeeperClient, IRateKeeperGetMeterResponse | |
} from 'voyager-shared'; | |
class RateKeeperClient { | |
public static createGrpcClient(host: string, port: number): IRateKeeperClient { | |
let protoPath: string = path.join('[relative-path-to]/ratekeeper.proto'); | |
let proto: any = grpc.load(protoPath).ratekeeper; | |
let connectionString: string = host + ':' + port; | |
return new proto.RateKeeperService(connectionString, grpc.credentials.createInsecure()); | |
} | |
} | |
// connect to the grpc server | |
let client: IRateKeeperClient = RateKeeperClient.createGrpcClient('0.0.0.0', 50051); | |
client.getMeter({ meterId: 'd83fa551-8030-416a-b443-306aef06a5d2' }, (error: any, response: IRateKeeperGetMeterResponse) => { | |
if (error) { | |
console.error(error); | |
process.exit(1); | |
} else { | |
console.log('meter:', (<IPublicCloudMeter>response.meter)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment