https://github.com/snapp-incubator/qsse
SSE over QUIC protocol
https://github.com/snapp-incubator/qsse
go golang http3 quic server-sent-events sse
Last synced: 3 months ago
JSON representation
SSE over QUIC protocol
- Host: GitHub
- URL: https://github.com/snapp-incubator/qsse
- Owner: snapp-incubator
- License: apache-2.0
- Created: 2022-05-07T08:46:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-06T06:49:09.000Z (6 months ago)
- Last Synced: 2025-06-23T04:41:32.561Z (4 months ago)
- Topics: go, golang, http3, quic, server-sent-events, sse
- Language: Go
- Homepage:
- Size: 631 KB
- Stars: 35
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

SSE Over QUIC
Implementation of Server Sent Events by QUIC. A faster replacement for traditional SSE over HTTP/2.
## Installation
```bash
go get github.com/snapp-incubator/qsse
```
## Basic Usage
### Server
```Go
// Server
package main
import "github.com/snapp-incubator/qsse"
var (
people = []Person{...}
accounts = []Account{...}
)
func main() {
topics := []string{"people", "account"}
server, err := qsse.NewServer("localhost:4242", topics, nil)
if err != nil {
panic(err)
}
// publish events
server.Publish("people", people[0])
server.Publish("accounts", accounts[0])
// ...
// some blocking code to keep the server up
}
```
### Client
```Go
package main
import "github.com/snapp-incubator/qsse"
func main() {
topics := []string{"people", "account"}
client, err := qsse.NewClient("localhost:4242", topics, nil)
if err != nil {
panic(err)
}
client.SetEventHandler("people", func(data []byte) {
// handle data on topic
})
client.SetErrorHandler(func(code int, data map[string]any) {
// handle different error
})
// some blocking code to keep the client up for receiving the events
}
```
## Security
By default, all the clients are accepted. Use Authentication to check is new clients are valid and use Authorization to check client access on each topic.
```Go
// authentication
// func
server.SetAuthenticatorFunc(func(token string) bool {
})
// interface
server.SetAuthenticator()
// authorization on each topic
// func
server.SetAuthorizerFunc(func(token, topic string) bool {
})
// interface
server.SetAuthorizer()
```
## Topic Patterns
topics can be separated by `.` logically. also `*` can be used as wildcard placeholder. for example these are valid topics
- `ride`
- `ride.*.start`
- `ride.passenger.*`
**Note**: Putting `*` at the end of topic will publish or subscribe to every topic that start with `*` prefix. For example `ride.passenger.*` is equivalent of subscribing to `ride.passenger.start`, `ride.passenger.account.name`, and so on.
## Server Configurations
| config | description | default |
|------------------------------------------|----------------------------------------------------------------------------------------------- |-------------------------------- |
| Metric.namespace,
Metric.subsystem | namespace and subsystem parameters of the Prometheus metrics | "qsse",
"qsse" |
| TLSConfig | TLS config of server | qsse.GetDefaultTLSConfig
() |
| Worker.CleaningInterval | interval between cleaning idle clients | 10 sec |
| Worker.ClientAcceptorCount | number of Goroutine accepting new clients | 1 |
| Worker.ClientAcceptorQueueSize | queue size of client acceptors. (this is usually equal to `clientAcceptorCount`) | 1 |
| Worker.EventDistributorCount | number of concurrent goroutine distributing events to subscribers for each EventSource[topic] | 1 |
| Worker.EventDistributorQueueSize | queue size of event distribution work | 10 |
## Client Configurations
| config | description | default |
|------------------------------- |------------------------------------------------------------------------------------------------------ |------------------------- |
| token | token that will be send to server on the initial connection to verify the client. | "" |
| TLSConfig | TLS config of client | qsse.GetSimpleTLS
() |
| ReconnectPolicy.Retry | bool that indicate if client should retry connection if couldn't connect to server on the first try. | false |
| ReconnectPolicy.RetryTimes | number of reconnect times to connect. | 5 |
| ReconnectPolicy.RetryInterval | interval between reconnecting to server | 5 sec |
## Examples
- [Simple Client & Server](examples/simple)
- [Topic Patterns](examples/topic-pattern)
- [Multiple Generators](examples/multiple-generators)