Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release v4.0.0
v4 of this gem targets the current Centrifugo HTTP API (tested against Centrifugo v6) and drops the legacy
POST /apiJSON-RPC-style protocol the gem used through v3.Highlights
X-API-Keyheader).subscribe,refresh,history_remove,batch.publish/broadcastaccepttags,skip_history,idempotency_key,delta,version,version_epoch,b64data;historyacceptslimit,since,reverse;channelsacceptspattern;disconnectacceptsclient/session/whitelist/custom disconnect).Cent::TimeoutError,Cent::NetworkError,Cent::TransportError,Cent::UnauthorizedError,Cent::DecodeError.Cent::Notarycovering every standard and Centrifugo-specific JWT claim.Changes
Transport
POST /api/publish,POST /api/broadcast, and so on — instead of a singlePOST /apiendpoint with{"method": "...", "params": {...}}body.X-API-Key: <key>per current Centrifugo docs (previouslyAuthorization: apikey <key>).Cent::Client.newgained atimeout:keyword (default10seconds) that sets both open and read timeouts on the Faraday connection. The initializer still yields theFaraday::Connectionfor further customization.Cent::Client— new methodssubscribe(user:, channel:, ...)— server-side subscribe a user session to a channel.refresh(user:, ...)— refresh a connection (useful for unidirectional transports).history_remove(channel:)— remove all publications from a channel's history.batch(commands:, parallel: nil)— send many commands in one HTTP request; inspect each reply individually for errors. (The batch response is shaped{ "replies" => [...] }with no top-levelresultwrapper.)Cent::Client— expanded argumentspublish(channel:, data:, skip_history: nil, tags: nil, b64data: nil, idempotency_key: nil, delta: nil, version: nil, version_epoch: nil)broadcast(channels:, data:, skip_history: nil, tags: nil, b64data: nil, idempotency_key: nil, delta: nil, version: nil, version_epoch: nil)disconnect(user:, client: nil, session: nil, whitelist: nil, disconnect: nil)unsubscribe(user:, channel:, client: nil, session: nil)history(channel:, limit: nil, since: nil, reverse: nil)channels(pattern: nil)Any keyword passed as
nilis omitted from the request body.Cent::Client— return values and error handlingOn success every method returns the parsed Centrifugo response body — typically
{ "result" => { ... } }. If Centrifugo rejects the request with a top-levelerror,Cent::ResponseErroris raised (same class, samecode/messageattributes as v3) — your existingrescue Cent::ResponseErrorblocks keep working.Transport-level problems (network failure, timeout, non-2xx HTTP, bad JSON) raise the new typed errors described below.
batchandbroadcast— per-reply errors are not raisedbatchandbroadcastreturn an array of independent sub-replies; a single partial failure shouldn't short-circuit the whole response, so their per-reply errors are not turned into exceptions.batchresponse is{ "replies" => [...] }— note there is no top-levelresultwrapper. Each entry is either{ "<method>" => <result> }or{ "error" => {...} }.broadcastresponse has{ "result" => { "responses" => [...] } }. Each entry inresponsesis either{ "result" => {...} }or{ "error" => {...} }.Walk the array to check for per-entry errors.
Cent::ResponseErroris still raised for these calls if Centrifugo rejects the whole request (e.g. malformed top-level body).Errors
The error hierarchy has been expanded:
Cent::Error(base,StandardError)Cent::ResponseError— Centrifugo returned a top-level API error. Exposes#codeand#message. Unchanged from v3.Cent::TimeoutError— request timed out.Cent::NetworkError— could not reach Centrifugo.Cent::TransportError— non-2xx HTTP status. Exposes#status.Cent::UnauthorizedError— HTTP 401 (bad API key).Cent::DecodeError— response body was not valid JSON.All new errors subclass
Cent::Error, so a broadrescue Cent::Errorstill catches everything.Cent::NotaryBoth token methods now support every standard and Centrifugo-specific JWT claim:
issue_connection_token(sub:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, channels: nil, subs: nil, meta: nil, expire_at: nil)issue_channel_token(sub:, channel:, exp: nil, iat: nil, jti: nil, aud: nil, iss: nil, info: nil, b64info: nil, override: nil, expire_at: nil)The
client:keyword that used to be onissue_channel_tokenis replaced by the standardsub:claim (this was already done in v3 via #24 and is carried forward unchanged).Dependencies
>= 3.0(previously>= 2.5).CI and testing
ruby-headexperimental job tracking Ruby 4.gemfiles/for reproducing any matrix cell locally (bundle exec appraisal rspec).spec/integration/runs against a real Centrifugo instance. Unit tests continue to use WebMock.docker-compose.ymlat the repo root spins up Centrifugo v6.7.1 with history, presence, and the GRPC API enabled for local development.Migration from v3
Upgrade your Centrifugo server to v4 or newer. v4 of this gem speaks the current API and no longer works with pre-v4 Centrifugo.
rescue Cent::ResponseErrorkeeps working. No change needed. The class, its#code, and its#messageare preserved from v3.Consider switching to more specific transport-error rescues. If you previously rescued
Faraday::ClientErroror a broadCent::Error, you can now target specific classes:Cent::TimeoutError,Cent::NetworkError,Cent::UnauthorizedError,Cent::TransportError,Cent::DecodeError. The broadrescue Cent::Errorstill catches all of them.If you use
batchorbroadcast, inspect the reply arrays. Per-reply errors inresponse["replies"](batch) orresponse["result"]["responses"](broadcast) are returned as hash entries with an"error"key — they are not raised. See the README for examples.Update
Cent::Notary#issue_channel_tokencalls if you are coming from v2.x: theclient:keyword is nowsub:.Bump your Ruby to 3.0 or newer if you are on 2.x. Ruby 2.7 has been end-of-life since March 2023.
No changes required for existing happy-path calls.
client.publish(channel:, data:),broadcast(channels:, data:),presence,presence_stats,history(channel:),channels,info,disconnect(user:),unsubscribe(channel:, user:)all keep their v3 signatures (with optional new kwargs). The response shape ({ "result" => ... }) is unchanged on success.Thanks
Thanks to @alfonsouc (#27) and @trushkevich (#24) for the groundwork that landed ahead of this release.