Description
A wrapper around gorilla websocket that can channelize the websocket messages. It gives the client this option to receive events in different channels. Channelize is useful when your websocket server is reading different types of events from a message broker. e.g., you might have multiple kafka topics or NATs subjects.
Channelize gives you this option to categorize the outbound messages. You can choose a name for each event type and register them as a channel in the Channelize and send messages to those channels. Then client can subscribe to one or more channels to receive the streams.
channelize alternatives and similar packages
Based on the "Go Tools" category.
Alternatively, view channelize alternatives based on common mentions on social networks and blogs.
-
JuiceFS
JuiceFS is a distributed POSIX file system built on top of Redis and S3. -
JSON-to-Go
Translates JSON into a Go type in your browser instantly (original) -
gb
An easy to use project based build tool for the Go programming language. -
kube-prompt
An interactive kubernetes client featuring auto-complete. -
go-critic
The most opinionated Go source code linter for code audit. -
The Go Play Space
Advanced Go Playground frontend written in Go, with syntax highlighting, turtle graphics mode, and more -
Peanut
🐺 Deploy Databases and Services Easily for Development and Testing Pipelines. -
golang-tutorials
Golang Tutorials. Learn Golang from Scratch with simple examples. -
xdg-go
Go implementation of the XDG Base Directory Specification and XDG user directories -
rts
RTS: request to struct. Generates Go structs from JSON server responses. -
typex
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations. -
gothanks
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself. -
zb
an opinionated repo based tool for linting, testing and building go source -
Viney's go-cache
A flexible multi-layer Go caching library to deal with in-memory and shared cache by adopting Cache-Aside pattern. -
go-lock
go-lock is a lock library implementing read-write mutex and read-write trylock without starvation -
goroutines
It is an efficient, flexible, and lightweight goroutine pool. It provides an easy way to deal with concurrent tasks with limited resource. -
An exit strategy for go routines.
An exit strategy for go routines -
generator-go-lang
A Yeoman generator to get new Go projects started. -
import "github/shuLhan/share"
A collection of libraries and tools written in Go; including DNS, email, git ini file format, HTTP, memfs (embedding file into Go), paseto, SMTP, TOTP, WebSocket, XMLRPC, and many more. -
go-james
James is your butler and helps you to create, build, debug, test and run your Go projects -
version
Go package to present your CLI version with an upgrade notice. -
PDF to Image Converter Using Golang
This project will help you to convert PDF file to IMAGE using golang. -
go-sanitize
:bathtub: Golang library of simple to use sanitation functions -
go-whatsonchain
:link: Unofficial golang implementation for the WhatsOnChain API -
gomodrun
The forgotten go tool that executes and caches binaries included in go.mod files. -
docs
Automatically generate RESTful API documentation for GO projects - aligned with Open API Specification standard -
Proofable
General purpose proving framework for certifying digital assets to public blockchains -
ciiigo
[mirror] Go static website generator with asciidoc markup language -
redispubsub
Redis Streams queue driver for https://godoc.org/gocloud.dev/pubsub package -
MessageBus implementation for CQRS projects
CQRS Implementation for Golang language -
go-slices
Helper functions for the manipulation of slices of all types in Go -
modver
Compare two versions of a Go module to check the version-number change required (major, minor, or patchlevel), according to semver rules. -
go-pipl
:family_man_woman_boy: Unofficial golang implementation for the pipl.com search API -
go-polynym
:performing_arts: Unofficial golang implementation for the Polynym.io API
Static code analysis for 29 languages.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of channelize or a related project?
README
channelize
A wrapper around gorilla websocket that can channelize the websocket messages. It gives the client this option to receive events in different channels. Channelize is useful when your websocket server is reading different types of events from a message broker. e.g., you might have multiple kafka topics or NATs subjects.
Channelize gives you this option to categorize the outbound messages. You can choose a name for each event type and register them as a channel in the Channelize and send messages to those channels. Then client can subscribe to one or more channels to receive the streams.
[channelize](images/channelize.png?raw=true "channelize")
Table of Contents
Install
To use Channelize, first you should use go get
command to get the latest version of this library:
go get -u github.com/hmdsefi/channelize
Next step is importing channelize to your project:
import "github.com/hmdsefi/channelize"
How to use
To use Channelize, first you should know about the channel concept. A channel is a unique name for a stream of events that have the same type. A channel can be public or private. A public channel sends the outbound messages to the all available connections that subscribed to that channel. A private channel needs authentication, it sends the outbound messages to a specific connection that already subscribed to that private channel with a valid token.
Public channels
To use public channels, first you should register your public channels with one of the following functions:
channel := channelize.RegisterPublicChannel("my-public-channel")
channels := channelize.RegisterPublicChannels("my-public-channel1", "my-public-channel2")
Registering same channel more than once won't break anything. It will override the previous one. To send messages to the channels, you should create an instance of Channelize struct to be able to use the library APIs.
chlz := channelize.NewChannelize()
Then you can call the following function in your consumer function to send the messages to the proper channel:
err := chlz.SendPublicMessage(ctx, channel, message)
if err != nil {
return err
}
Channelize struct gives you this option to create your handler or using the handler that channelize creates for you. If you want to implement the handler by yourself, then you can use the following method:
connection := chlz.CreateConnection(ctx context.Context, wsConn *websocket.Conn, options ...conn.Option)
Or you can create the handler by calling the following method:
handler := chlz.MakeHTTPHandler(appCtx context.Context, upgrader websocket.Upgrader, options ...conn.Option)
To subscribe to one or more public channels, client should send the following message to the server:
{
"type": "subscribe",
"params": {
"channels": [
"my-public-channel1",
"my-public-channel2"
]
}
}
To unsubscribe one or more channels, client should send the following message to the server:
{
"type": "unsubscribe",
"params": {
"channels": [
"my-public-channel1"
]
}
}
Private channels
To use private channels, first you should register your private channels with one of the following functions:
channel := channelize.RegisterPrivateChannel("my-private-channel")
channels := channelize.RegisterPrivateChannels("my-private-channel1", "my-private-channel2")
Private channels need authentication. To provide authentication you should implement the function type that is defined
in auth
package:
type AuthenticateFunc func (token string) (*Token, error)
Then you should pass as an option to the Channelize constructor:
chlz := channelize.NewChannelize(channelize.WithAuthFunc(MyAuthFunc)))
You can use CreateConnection
or MakeHTTPHandler
to create the connection for the client just like public channels.
To send the message to the client you should use the following function:
err := chlz.SendPrivateMessage(ctx, channel, userID, message)
if err != nil {
return err
}
To subscribe to private channels, client should fill the token field with the proper value:
{
"type": "subscribe",
"params": {
"channels": [
"my-public-channel1",
"my-private-channel1"
],
"token": "618bb5b00161cbd68bc744b2ea84c96601d6705f31cc7d32e01c3371f6e7"
}
}
To unsubscribe, client can use the following message:
{
"type": "unsubscribe",
"params": {
"channels": [
"my-private-channel1"
]
}
}
License
MIT License, please see LICENSE for details.
*Note that all licence references and agreements mentioned in the channelize README section above
are relevant to that project's source code only.