Menu
Open source
Stream.end()
Caution
Starting on k6
v0.49
, the experimental modulek6/experimental/grpc
has been graduated, and its functionality is now available in thek6/net/grpc
module. Thek6/experimental/grpc
is deprecated and will be removed inv0.51.0
.To migrate your scripts, replace all
k6/experimental/grpc
imports withk6/net/grpc
.
Signals to the server that the client has finished sending messages.
Example
JavaScript
import { Client, Stream } from 'k6/experimental/grpc';
import { sleep } from 'k6';
const COORD_FACTOR = 1e7;
const client = new Client();
client.load([], '../../grpc_server/route_guide.proto');
export default () => {
if (__ITER == 0) {
client.connect('127.0.0.1:10000', { plaintext: true });
}
const stream = new Stream(client, 'main.RouteGuide/RecordRoute');
stream.on('data', (stats) => {
console.log('Finished trip with', stats.pointCount, 'points');
console.log('Passed', stats.featureCount, 'features');
console.log('Traveled', stats.distance, 'meters');
console.log('It took', stats.elapsedTime, 'seconds');
});
// send 2 items
stream.write({ latitude: 406109563, longitude: -742186778 });
stream.write({ latitude: 416802456, longitude: -742370183 });
// send end-signal to the server
stream.end();
sleep(1);
};
Was this page helpful?
Related documentation
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video
Performance testing and observability in Grafana Cloud
In this webinar, learn how Grafana Cloud k6 offers you the best developer experience for performance testing.
User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.