No results for

Powered byAlgolia

k6/net/grpc

suggest edits

The k6/net/grpc module, added in k6 v0.29.0, provides a gRPC client for Remote Procedure Calls (RPC) over HTTP/2.

warning!

The k6 gRPC API is currently considered in beta and is subject to change. Future k6 versions might have slight differences in the method and type signatures described in this documentation.

Class/MethodDescription
ClientgRPC client used for making RPC calls to a gRPC Server.
Client.load(importPaths, ...protoFiles)Loads and parses the given protocol buffer definitions to be made available for RPC requests.
Client.connect(address [,params])Connects to a given gRPC service.
Client.invoke(url, request [,params])Makes an unary RPC for the given service/method and returns a Response.
Client.close()Close the connection to the gRPC service.
ParamsRPC Request specific options.
ResponseReturned by RPC requests.
ConstantsDefine constants to distinguish between gRPC Response statuses.

Example

grpc-test.js
import grpc from 'k6/net/grpc';
const client = new grpc.Client();
client.load(['definitions'], 'hello.proto');
export default () => {
client.connect('grpcb.in:9001', {
// plaintext: false
});
const data = { greeting: 'Bert' };
const response = client.invoke('hello.HelloService/SayHello', data);
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});
console.log(JSON.stringify(response.message));
client.close();
sleep(1);
};