Skip to content

Commit

Permalink
Adding comments to Update grpc.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordiancyber authored Oct 31, 2023
1 parent 61db2fe commit e18fe18
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions examples/grpc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
// Import gRPC and k6 check module for use in the script.

import grpc from 'k6/net/grpc';
import { check } from "k6";

// Create a new gRPC client and load the protocol buffer definition.

let client = new grpc.Client();
client.load([], "./grpc_server/route_guide.proto")
client.load([], "./grpc_server/route_guide.proto");

// Define the default k6 script.

export default () => {
client.connect("127.0.0.1:10000", { plaintext: true })
// Connect to the gRPC server at 127.0.0.1:10000 using plaintext.

client.connect("127.0.0.1:10000", { plaintext: true });

// Invoke the "main.FeatureExplorer/GetFeature" method with specific latitude and longitude values.

const response = client.invoke("main.FeatureExplorer/GetFeature", {
latitude: 410248224,
longitude: -747127767
})
});

// Check the response for an "OK" status using the gRPC status code.

check(response, { "status is OK": (r) => r && r.status === grpc.StatusOK });
console.log(JSON.stringify(response.message))

client.close()
// Log the response message as a JSON string.

console.log(JSON.stringify(response.message));

// Close the gRPC client connection.
client.close();
}

0 comments on commit e18fe18

Please sign in to comment.