Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
The address of the gRPC server. Should be in the form: host:port with no protocol prefix e.g. grpc.k6.io:443. The host must be a literal IP address, or a host name that can be resolved to IP addresses. The port must be a literal port number or a service name e.g. :443 or :https. If the host is a literal IPv6 address it must be enclosed in square brackets, as in [2001:db8::1]:80 or [fe80::1%zone]:80.
Object with key-value pairs representing custom metadata the user would like to add to the reflection request.
ConnectParams.timeout
string / number
Connection timeout to use. Default timeout is "60s". The type can also be a number, in which case k6 interprets it as milliseconds, e.g., 60000 is equivalent to "60s".
ConnectParams.maxReceiveSize
number
Sets the maximum message size in bytes the client can receive. Defaults to grpc-go default, which is 4MB.
ConnectParams.maxSendSize
number
Sets the maximum message size in bytes the client can send. Defaults to grpc-go default, which is approximately 2GB.
import grpc from'k6/experimental/grpc';import{ check }from'k6';import{ SharedArray }from'k6/data';import exec from'k6/execution';// note: the services in this example don't exist. If you would like// to run this example, make sure to replace the URLs, and// the cacerts, cert, key, and password variables.const grpcArgs =newSharedArray('grpc',()=>{// Using SharedArray here so that not every VU gets a copy of every certificate a keyreturn[{host:'foo1.grpcbin.test.k6.io:9001',plaintext:false,params:{tls:{cacerts:[open('cacerts0.pem')],cert:open('cert0.pem'),key:open('key0.pem'),},},},{host:'foo2.grpcbin.test.k6.io:9002',params:{plaintext:false,tls:{cacerts:open('cacerts1.pem'),cert:open('cert1.pem'),key:open('key1.pem'),password:'cert1-passphrase',},},},];});const client =newgrpc.Client();exportdefault()=>{if(__ITER ===0){// Take one config and use it for this one VUconst grpcArg = grpcArgs[exec.vu.idInTest % grpcArgs.length];
client.connect(grpcArg.host, grpcArg.params);}const response = client.invoke('hello.HelloService/SayHello',{greeting:'Bert',});check(response,{'status is OK':(r)=> r && r.status === grpc.StatusOK,});
console.log(JSON.stringify(response.message));};