Menu

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.

Open source

Stream.write()

Caution

Starting on k6 v0.49, the experimental module k6/experimental/grpc has been graduated, and its functionality is now available in the k6/net/grpc module. The k6/experimental/grpc is deprecated and will be removed in v0.51.0.

To migrate your scripts, replace all k6/experimental/grpc imports with k6/net/grpc.

Writes a message to the stream.

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');
  });

  // send an item
  stream.write({ latitude: 406109563, longitude: -742186778 });

  // send end-signal to the server
  stream.end();

  sleep(1);
};