Skip to content

Commit

Permalink
Merge branch 'master' into last_message_recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Mar 23, 2024
2 parents 8917541 + 23c243d commit 76b3595
Show file tree
Hide file tree
Showing 60 changed files with 5,821 additions and 818 deletions.
1 change: 1 addition & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage:
ignore:
- "internal/controlpb/control*" # generated code
- "client_experimental.go" # experimental code
- "internal/websocket/*" # embedded Gorilla WebSocket fork
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20.x'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.53.3
args: --timeout 3m0s
Expand All @@ -27,7 +27,7 @@ jobs:
redis-version: [5, 6, 7]
steps:
- name: Install Go stable version
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand All @@ -44,6 +44,6 @@ jobs:

- name: Upload code coverage to codecov
if: matrix.go-version == '1.21'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Library highlights:

* Fast and optimized for low-latency communication with millions of client connections. See [test stand with 1 million connections in Kubernetes](https://centrifugal.dev/blog/2020/02/10/million-connections-with-centrifugo)
* WebSocket bidirectional transport using JSON or binary Protobuf formats, both based on a [strict Protobuf schema](https://github.com/centrifugal/protocol/blob/master/definitions/client.proto). Code generation is used to push both JSON and Protobuf serialization performance to the limits
* Our [own WebSocket emulation layer](https://centrifugal.dev/blog/2022/07/19/centrifugo-v4-released#modern-websocket-emulation-in-javascript) over HTTP-streaming (JSON + Protobuf) and Eventsource (JSON) without sticky sessions requirement for distributed setup, or SockJS (JSON only)
* Our [own WebSocket emulation layer](https://centrifugal.dev/blog/2022/07/19/centrifugo-v4-released#modern-websocket-emulation-in-javascript) over HTTP-streaming (JSON + Protobuf) and Eventsource (JSON) without sticky sessions requirement for distributed setup
* Possibility to use unidirectional transports without using custom Centrifuge SDK library: see examples for [GRPC](https://github.com/centrifugal/centrifuge/tree/master/_examples/unidirectional_grpc), [EventSource(SSE)](https://github.com/centrifugal/centrifuge/tree/master/_examples/unidirectional_sse), [HTTP-streaming](https://github.com/centrifugal/centrifuge/tree/master/_examples/unidirectional_http_stream), [Unidirectional WebSocket](https://github.com/centrifugal/centrifuge/tree/master/_examples/unidirectional_ws)
* Built-in horizontal scalability with Redis PUB/SUB, consistent Redis sharding, Redis Sentinel and Redis Cluster support, [super-optimized Redis communication layer](https://centrifugal.dev/blog/2022/12/20/improving-redis-engine-performance)
* Effective non-blocking broadcasts towards client connections using individual queues
Expand All @@ -30,13 +30,16 @@ Library highlights:
* Out-of-the-box Prometheus instrumentation
* Client SDKs for main application environments all following [single behaviour spec](https://centrifugal.dev/docs/transports/client_api) (see list of SDKs below).

### Real-time SDK

For **bidirectional** communication between a client and a Centrifuge-based server we have a set of official client real-time SDKs:

* [centrifuge-js](https://github.com/centrifugal/centrifuge-js) – for a browser, NodeJS and React Native
* [centrifuge-go](https://github.com/centrifugal/centrifuge-go) - for Go language
* [centrifuge-dart](https://github.com/centrifugal/centrifuge-dart) - for Dart and Flutter
* [centrifuge-swift](https://github.com/centrifugal/centrifuge-swift) – for native iOS development
* [centrifuge-java](https://github.com/centrifugal/centrifuge-java) – for native Android development and general Java
* [centrifuge-python](https://github.com/centrifugal/centrifuge-python) - real-time SDK for Python on top of asyncio

These SDKs abstract asynchronous communication complexity from the developer: handle framing, reconnect with backoff, timeouts, multiplex channel subscriptions over single connection, etc.

Expand Down Expand Up @@ -244,7 +247,7 @@ Some useful advices about library here.

Let's describe some aspects related to connection life cycle and event handling in Centrifuge:

* If you set middleware for transport handlers (`WebsocketHandler`, `SockjsHandler`) – then it will be called first before a client sent any command to a server and handler had a chance to start working. Just like a regular HTTP middleware. You can put `Credentials` to `Context` to authenticate connection.
* If you set middleware for transport handlers (like `WebsocketHandler`) – then it will be called first before a client sent any command to a server and handler had a chance to start working. Just like a regular HTTP middleware. You can put `Credentials` to `Context` to authenticate connection.
* `node.OnConnecting` called as soon as client sent `Connect` command to server. At this point no `Client` instance exists. You have incoming `Context` and `Transport` information. You still can authenticate Client at this point (based on string token sent from client side or any other way). Also, you can add extra data to context and return modified context to Centrifuge. Context cancelled as soon as client connection closes. This handler is synchronous and connection read loop can't proceed until you return `ConnectReply`.
* `node.OnConnect` then called (after a reply to `Connect` command already written to connection). Inside `OnConnect` closure you have a possibility to define per-connection event handlers. If particular handler not set then client will get `ErrorNotAvailable` errors requesting it. Remember that none of event handlers available in Centrifuge should block forever – do minimal work, start separate goroutines if you need blocking code.
* Client initiated request handlers called one by one from connection reading goroutine. This includes `OnSubscribe`, `OnPublish`, `OnPresence`, `OnPresenceStats`, `OnHistory`, client-side `OnRefresh`, client-side `OnSubRefresh`.
Expand Down
8 changes: 0 additions & 8 deletions _examples/chat_json/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,6 @@ func main() {
})
mux.Handle("/connection/websocket", authMiddleware(websocketHandler))

sockjsHandler := centrifuge.NewSockjsHandler(node, centrifuge.SockjsConfig{
URL: "https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js",
HandlerPrefix: "/connection/sockjs",
WebsocketReadBufferSize: 1024,
WebsocketWriteBufferSize: 1024,
})
mux.Handle("/connection/sockjs/", authMiddleware(sockjsHandler))

mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/", http.FileServer(http.Dir("./")))

Expand Down
8 changes: 0 additions & 8 deletions _examples/concurrency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,6 @@ func main() {
})
http.Handle("/connection/websocket", authMiddleware(websocketHandler))

sockjsHandler := centrifuge.NewSockjsHandler(node, centrifuge.SockjsConfig{
URL: "https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js",
HandlerPrefix: "/connection/sockjs",
WebsocketReadBufferSize: 1024,
WebsocketWriteBufferSize: 1024,
})
http.Handle("/connection/sockjs/", authMiddleware(sockjsHandler))

http.Handle("/", http.FileServer(http.Dir("./")))

go func() {
Expand Down
2 changes: 1 addition & 1 deletion _examples/custom_engine_tarantool/tntengine/presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ type removePresenceRequest struct {
ClientID string
}

func (m PresenceManager) RemovePresence(ch string, clientID string) error {
func (m PresenceManager) RemovePresence(ch string, clientID string, _ string) error {
s := consistentShard(ch, m.shards)
_, err := s.Exec(tarantool.Call("centrifuge.remove_presence", removePresenceRequest{Channel: ch, ClientID: clientID}))
return err
Expand Down
4 changes: 1 addition & 3 deletions _examples/gin_auth/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Example demonstrates a simple chat with JSON protocol sharing session auth with [gin-gonic](https://github.com/gin-gonic/gin).

Client uses Websocket by default, but you can simply uncomment one line in `chat.html` to use SockJS instead.

To start example run the following command from example directory:

```
Expand All @@ -15,4 +13,4 @@ There is only one email/pass combination : `[email protected]:password`

[gin-gonic]: https://github.com/gin-gonic/gin

_Credits to the example by FZambia from whom I took most of the centrifuge code_
_Credits to the example by FZambia from whom I took most of the centrifuge code_
30 changes: 14 additions & 16 deletions _examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ require (
github.com/FZambia/tarantool v0.2.2
github.com/centrifugal/centrifuge v0.8.2
github.com/centrifugal/protocol v0.12.1-0.20240323055736-2bac99578c1f
github.com/cristalhq/jwt/v3 v3.0.0
github.com/cristalhq/jwt/v5 v5.4.0
github.com/dchest/uniuri v1.2.0
github.com/evanphx/json-patch/v5 v5.9.0
github.com/gin-contrib/sessions v0.0.3
github.com/gin-gonic/gin v1.9.1
github.com/gobwas/ws v1.3.1
github.com/google/uuid v1.5.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/sessions v1.2.1
github.com/gorilla/websocket v1.5.0
github.com/mailru/easygo v0.0.0-20190618140210-3c14a0dc985f
github.com/nats-io/nats.go v1.31.0
github.com/prometheus/client_golang v1.17.0
github.com/quic-go/quic-go v0.40.0
github.com/prometheus/client_golang v1.19.0
github.com/quic-go/quic-go v0.40.1
github.com/shadowspore/fossil-delta v0.0.0-20240102155221-e3a8590b820b
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/vmihailenco/msgpack/v5 v5.4.1
golang.org/x/oauth2 v0.14.0
golang.org/x/oauth2 v0.16.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.33.0
nhooyr.io/websocket v1.8.10
Expand Down Expand Up @@ -53,15 +53,13 @@ require (
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/igm/sockjs-go/v3 v3.0.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nats-io/nkeys v0.4.6 // indirect
Expand All @@ -70,12 +68,12 @@ require (
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
github.com/redis/rueidis v1.0.25 // indirect
github.com/redis/rueidis v1.0.31 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/segmentio/encoding v0.4.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand All @@ -84,12 +82,12 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.uber.org/mock v0.3.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading

0 comments on commit 76b3595

Please sign in to comment.