Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phymbert/xk6-sse
A k6 extension for Server-Sent Events (SSE)
https://github.com/phymbert/xk6-sse
k6 sse sse-client xk6 xk6-extension
Last synced: 4 months ago
JSON representation
A k6 extension for Server-Sent Events (SSE)
- Host: GitHub
- URL: https://github.com/phymbert/xk6-sse
- Owner: phymbert
- License: apache-2.0
- Created: 2024-04-04T17:44:27.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-07-24T19:25:23.000Z (5 months ago)
- Last Synced: 2024-07-24T22:18:32.442Z (5 months ago)
- Topics: k6, sse, sse-client, xk6, xk6-extension
- Language: Go
- Homepage:
- Size: 97.7 KB
- Stars: 12
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-k6 - xk6-sse - A k6 extension for Server-Sent Events (SSE). (Extensions / Community)
- awesome-k6 - xk6-sse - A k6 extension for Server-Sent Events (SSE). (Extensions / Community)
README
# xk6-sse
A [k6](https://go.k6.io/k6) extension for [Server-Sent Events (SSE)](https://en.wikipedia.org/wiki/Server-sent_events) using the [xk6](https://github.com/grafana/xk6) system.See the [K6 SSE Extension design](docs/design/021-sse-api.md).
## k6 version
This extension is tested with `k6` version `v0.51.0` last release is [v0.1.2](https://github.com/phymbert/xk6-sse/releases/tag/v0.1.2).
## Build
To build a `k6` binary with this plugin, first ensure you have the prerequisites:
- [Go toolchain](https://go101.org/article/go-toolchain.html)
- GitThen:
1. Install [xk6](https://github.com/grafana/xk6):
```shell
go install go.k6.io/xk6/cmd/xk6@latest
```2. Build the binary:
```shell
xk6 build master \
--with github.com/phymbert/xk6-sse
```## Example
```javascript
import sse from "k6/x/sse"
import {check} from "k6"export default function () {
const url = "https://echo.websocket.org/.sse"
const params = {
method: 'GET',
headers: {
"Authorization": "Bearer XXXX"
},
tags: {"my_k6s_tag": "hello sse"}
}const response = sse.open(url, params, function (client) {
client.on('open', function open() {
console.log('connected')
})client.on('event', function (event) {
console.log(`event id=${event.id}, name=${event.name}, data=${event.data}`)
if (parseInt(event.id) === 4) {
client.close()
}
})client.on('error', function (e) {
console.log('An unexpected error occurred: ', e.error())
})
})check(response, {"status is 200": (r) => r && r.status === 200})
}
```### License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/