-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8612ba0
commit 23ec317
Showing
5 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
docs/sources/next/javascript-api/k6-net-grpc/stream/event-handler.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: 'Event Handler' | ||
description: 'The handler function for various events on the gRPC stream.' | ||
weight: 50 | ||
--- | ||
|
||
# Event Handler | ||
|
||
The function to call for various events on the gRPC stream. It is set up using the [`stream.on()`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-net-grpc/stream/stream-on) method. | ||
|
||
| Name | Type | Description | | ||
| ---------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | | ||
| `data` | object or [`Error`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-net-grpc/stream/stream-error) | It's either object with the data from server (a message) or an error object, in case of `error` event | | ||
| `metadata` | [`Metadata`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-net-grpc/stream/message-metadata) | The object that represents the gRPC stream's message metadata. | | ||
|
||
### Example | ||
|
||
<div class="code-group" data-props='{"labels": ["A handler metadata example"], "lineNumbers": [true]}'> | ||
|
||
```javascript | ||
import { Client, Stream } from 'k6/net/grpc'; | ||
import { sleep } from 'k6'; | ||
|
||
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'); | ||
|
||
// sets up a handler for the data (server sends data) event | ||
stream.on('data', (stats, metadata) => { | ||
console.log('It took', stats.elapsedTime, 'seconds'); | ||
console.log('This message has been received:', metadata.ts); | ||
}); | ||
|
||
stream.on('end', function () { | ||
// The server has finished sending | ||
client.close(); | ||
}); | ||
|
||
sleep(1); | ||
}; | ||
``` | ||
|
||
</div> |
48 changes: 48 additions & 0 deletions
48
docs/sources/next/javascript-api/k6-net-grpc/stream/message-metadata.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: 'Metadata' | ||
description: "The metadata of a gRPC stream's message." | ||
weight: 60 | ||
--- | ||
|
||
# Metadata | ||
|
||
The `Metadata` is an object that represents the gRPC stream's message. | ||
|
||
| Name | Type | Description | | ||
| ------------- | ------ | -------------------------------------------------------------------------------------------- | | ||
| `Metadata.ts` | number | Contains the timestamp of the original event. For example, when a message has been received. | | ||
|
||
### Example | ||
|
||
<div class="code-group" data-props='{"labels": ["A handler metadata example"], "lineNumbers": [true]}'> | ||
|
||
```javascript | ||
import { Client, Stream } from 'k6/net/grpc'; | ||
import { sleep } from 'k6'; | ||
|
||
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'); | ||
|
||
// sets up a handler for the data (server sends data) event | ||
stream.on('data', (stats, metadata) => { | ||
console.log('It took', stats.elapsedTime, 'seconds'); | ||
console.log('This message has been received:', metadata.ts); | ||
}); | ||
|
||
stream.on('end', function () { | ||
// The server has finished sending | ||
client.close(); | ||
}); | ||
|
||
sleep(1); | ||
}; | ||
``` | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters