This file contains 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
/** | |
* Starts an RPC server that receives requests for the Greeter service at the | |
* sample server port | |
*/ | |
function main() { | |
var server = new grpc.Server(); | |
server.addService(hello_proto.Greeter.service, {sayHello: sayHello}); | |
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); | |
server.start(); | |
} |
This file contains 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
/** | |
* Implements the SayHello RPC method. | |
*/ | |
function sayHello(call, callback) { | |
sleep.sleep(getRandomInt(5)); | |
callback(null, {message: 'Hello ' + call.request.name}); | |
} |
This file contains 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
require('@google-cloud/trace-agent').start({ | |
projectId: '<GCP project ID>' | |
}); //Stackdriver Trace Agent |
This file contains 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
app.get('/', (req, res) => { | |
console.log('Inbound request received!'); |
This file contains 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
// make grpc call to grpc server - localhost on port 50051 | |
var client = new hello_proto.Greeter('localhost:50051', grpc.credentials.createInsecure()); | |
var user; | |
if (process.argv.length >= 3) { | |
user = process.argv[2]; | |
console.log("user is " + user); | |
} else { | |
user = 'world'; | |
} |
This file contains 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
client.sayHello({name: user}, function(err, response) { | |
if (err){ | |
console.log("could not get grpc response"); | |
res.send("could not get grpc response"); | |
return; | |
} | |
console.log('Greeting:', response.message); | |
res.send("grpc response is " + response.message); |
This file contains 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
require('@google-cloud/trace-agent').start({ | |
projectId: '<projectID>' | |
}); //Stackdriver Trace Agent |
This file contains 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
function sayHello(call, callback) { | |
sleep.sleep(getRandomInt(5)); | |
callback(null, {message: 'Hello ' + call.request.name}); | |
} |
This file contains 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
app.get('/', (req, res) => { | |
const delay = getRandomInt(5000); | |
console.log('request made'); | |
blockCpuFor(delay); | |
res.send('Delayed for ' + delay); | |
}) | |
app.listen(8080, () => console.log(`Example app listening on port 8080!`)) |
This file contains 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
function blockCpuFor(ms) { | |
var now = new Date().getTime(); | |
var result = 0 | |
var shouldRun = true; | |
while(shouldRun) { | |
result += Math.random() * Math.random(); | |
if (new Date().getTime() > now +ms) | |
return; | |
} | |
} |
OlderNewer