All Projects → r3labs → Sse

r3labs / Sse

Licence: mpl-2.0
Server Sent Events server and client for Golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Sse

Spring 5 Examples
This repository is contains spring-boot 2 / spring framework 5 project examples. Using reactive programming model / paradigm and Kotlin
Stars: ✭ 87 (-63.45%)
Mutual labels:  sse
Wechat Admin
Wechat Management System
Stars: ✭ 1,716 (+621.01%)
Mutual labels:  sse
Ugm
Ubpa Graphics Mathematics
Stars: ✭ 178 (-25.21%)
Mutual labels:  sse
Ray
Small pathtracing library with GPU and CPU backends
Stars: ✭ 95 (-60.08%)
Mutual labels:  sse
Tensorflow Optimized Wheels
TensorFlow wheels built for latest CUDA/CuDNN and enabled performance flags: SSE, AVX, FMA; XLA
Stars: ✭ 118 (-50.42%)
Mutual labels:  sse
Shotgun
For the times you need more than just a gun.
Stars: ✭ 158 (-33.61%)
Mutual labels:  sse
Ozz Animation
Open source c++ skeletal animation library and toolset
Stars: ✭ 1,250 (+425.21%)
Mutual labels:  sse
Sse Popcount
SIMD (SSE) population count --- http://0x80.pl/articles/sse-popcount.html
Stars: ✭ 226 (-5.04%)
Mutual labels:  sse
Lib.aspnetcore.serversentevents
Lib.AspNetCore.ServerSentEvents is a library which provides Server-Sent Events (SSE) support for ASP.NET Core
Stars: ✭ 138 (-42.02%)
Mutual labels:  sse
Server Push Hooks
🔥 React hooks for Socket.io, SEE, WebSockets and more to come
Stars: ✭ 176 (-26.05%)
Mutual labels:  sse
Demo Spring Sse
'Server-Sent Events (SSE) in Spring 5 with Web MVC and Web Flux' article and source code.
Stars: ✭ 102 (-57.14%)
Mutual labels:  sse
Sse4 Strstr
SIMD (SWAR/SSE/SSE4/AVX2/AVX512F/ARM Neon) of Karp-Rabin algorithm's modification
Stars: ✭ 115 (-51.68%)
Mutual labels:  sse
Unifrost
Making it easier to push pubsub events directly to the browser.
Stars: ✭ 166 (-30.25%)
Mutual labels:  sse
Despacer
C library to remove white space from strings as fast as possible
Stars: ✭ 90 (-62.18%)
Mutual labels:  sse
Toys
Storage for my snippets, toy programs, etc.
Stars: ✭ 187 (-21.43%)
Mutual labels:  sse
Simd
C++ image processing and machine learning library with using of SIMD: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, AVX-512, VMX(Altivec) and VSX(Power7), NEON for ARM.
Stars: ✭ 1,263 (+430.67%)
Mutual labels:  sse
Hlslpp
Math library using hlsl syntax with SSE/NEON support
Stars: ✭ 153 (-35.71%)
Mutual labels:  sse
Selenoid Ui
Graphical user interface for Selenoid project
Stars: ✭ 237 (-0.42%)
Mutual labels:  sse
Turbo Run Length Encoding
TurboRLE-Fastest Run Length Encoding
Stars: ✭ 212 (-10.92%)
Mutual labels:  sse
Lucid
High performance and distributed KV store w/ REST API. 🦀
Stars: ✭ 171 (-28.15%)
Mutual labels:  sse

SSE - Server Sent Events Client/Server Library for Go

Synopsis

SSE is a client/server implementation for Server Sent Events for Golang.

Build status

  • Master: CircleCI  Master

NOTE: All active development now takes place on the v2 branch.

Quick start

To install version 2:

go get github.com/r3labs/sse/v2

To Test:

$ make deps
$ make test

Example Server

There are two parts of the server. It is comprised of the message scheduler and a http handler function. The messaging system is started when running:

func main() {
	server := sse.New()
}

To add a stream to this handler:

func main() {
	server := sse.New()
	server.CreateStream("messages")
}

This creates a new stream inside of the scheduler. Seeing as there are no consumers, publishing a message to this channel will do nothing. Clients can connect to this stream once the http handler is started by specifying stream as a url parameter, like so:

http://server/events?stream=messages

In order to start the http server:

func main() {
	server := sse.New()

	// Create a new Mux and set the handler
	mux := http.NewServeMux()
	mux.HandleFunc("/events", server.HTTPHandler)

	http.ListenAndServe(":8080", mux)
}

To publish messages to a stream:

func main() {
	server := sse.New()

	// Publish a payload to the stream
	server.Publish("messages", &sse.Event{
		Data: []byte("ping"),
	})
}

Please note there must be a stream with the name you specify and there must be subscribers to that stream

Example Client

The client exposes a way to connect to an SSE server. The client can also handle multiple events under the same url.

To create a new client:

func main() {
	client := sse.NewClient("http://server/events")
}

To subscribe to an event stream, please use the Subscribe function. This accepts the name of the stream and a handler function:

func main() {
	client := sse.NewClient("http://server/events")

	client.Subscribe("messages", func(msg *sse.Event) {
		// Got some data!
		fmt.Println(msg.Data)
	})
}

Please note that this function will block the current thread. You can run this function in a go routine.

If you wish to have events sent to a channel, you can use SubscribeChan:

func main() {
	events := make(chan *sse.Event)

	client := sse.NewClient("http://server/events")
	client.SubscribeChan("messages", events)
}

HTTP client parameters

To add additional parameters to the http client, such as disabling ssl verification for self signed certs, you can override the http client or update its options:

func main() {
	client := sse.NewClient("http://server/events")
	client.Connection.Transport =  &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
}

URL query parameters

To set custom query parameters on the client or disable the stream parameter altogether:

func main() {
	client := sse.NewClient("http://server/events?search=example")

	client.SubscribeRaw(func(msg *sse.Event) {
		// Got some data!
		fmt.Println(msg.Data)
	})
}

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

Moreover, if your pull request contains patches or features, you must include relevant unit tests.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, this project is maintained under the Semantic Versioning guidelines.

Copyright and License

Code and documentation copyright since 2015 r3labs.io authors.

Code released under the Mozilla Public License Version 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].