Skip to main content

Crate cent

Crate cent 

Source
Expand description

The Rust SDK for the HTTP server API of Centrifugo: every API method, including those of Centrifugo PRO; tokens; proxy handlers and the endpoints client SDKs call.

use cent::{Client, Config, PublishRequest};

let client = Client::new(Config::new("http://localhost:8000/api").api_key("secret"))?;
let data = cent::json(&serde_json::json!({"text": "hello"}))?;
let res = client.publish(PublishRequest::new("news").data(data)).await?;
println!("published at offset {}", res.offset);

§The client

Client - and blocking::Client, with the blocking feature - has a method per API method, taking its request and returning its result, both generated from Centrifugo’s api.proto. A request’s new takes the fields Centrifugo requires; a method per field sets the others: PublishRequest::new("news").data(data).idempotency_key("k").

  • Payloads are JSON, as RawValue: kept exactly - number text included - in requests and results alike, so a payload from a reply goes back out as the same JSON value. JSON null is Some of a null; unset is None. serde_json writes NaN and infinities as null: check floats before encoding them. Write integers which may pass 2^53 as JSON strings: browsers decode JSON numbers as doubles. json encodes any serde type as a payload, and PayloadExt::decode decodes one: .data(cent::json(&message)?), publication.data.decode::<Message>()?.
  • One deadline per call: Config::request_timeout, or the call’s own Client::with_timeout, which replaces it; a Client::with_deadline only shortens it, never extends it. Every timeout is Error::Timeout.
  • Every call returns an error unless it did everything asked. A broadcast or batch in which some parts failed returns Error::BroadcastFailedChannels or Error::BatchFailedCommands, holding every part’s outcome - see Client::broadcast and Batch.
  • Retries: retryable says whether a new attempt may succeed; retry a publication only with the same idempotency_key, so that it is not published twice. Client::broadcast_with_retry retries only the channels which may still succeed. Centrifugo remembers a key per channel for five minutes by default, and a second publication under the same key is not published: a key derived from an entity must name the event too, order-42-paid rather than order-42. The memory, Redis and PostgreSQL brokers keep keys; the NATS broker ignores them.
  • Automatic batching: AutoBatch sends concurrent calls together once enough requests are in flight, never waiting for a timer.
  • Shutdown: Client::close refuses new calls and waits for those in progress.
  • Tests of code using the client need no Centrifugo: give it an HttpClient answering as Centrifugo does - see the README.

§Tokens, proxy handlers, endpoints

token signs connection, subscription and Centrifugo PRO server API tokens, and builds JWKS. proxy answers Centrifugo’s HTTP proxy; endpoints serves what the getToken and getSignature callbacks of client SDKs call, and JWKS; sharedpoll signs shared poll subscriptions. Each endpoint is a Handler - one function from an http::Request<Bytes> to a response, served from any framework, and a tower::Service with the tower feature. Command writes API calls for Centrifugo’s async consumers.

§Features

FeatureDefaultWhat
clientyesThe async Client, on tokio, with hyper and rustls
tokenyestoken, sharedpoll, and the JWKS endpoint
blockingblocking::Client
towerHandler as a tower::Service

cent implements the Centrifugo server SDK specification, version 0.4.

Re-exports§

pub use token::Expiry;token

Modules§

blockingblocking
A blocking client, for code without an async runtime.
endpoints
The endpoints client SDKs call: what their getToken callbacks fetch for connection and subscription tokens, what a shared poll subscription’s getSignature callback fetches, and the JWKS endpoint Centrifugo fetches public keys from.
proxy
The backend side of Centrifugo’s HTTP proxy, which calls the application when a client connects, subscribes, publishes or makes an RPC call: a Handler per proxy type, built from a function taking the decoded request and returning a result or a Rejection.
sharedpolltoken
Signatures for shared poll subscriptions, which clients tracking keys of a shared poll channel need from the backend. Shared poll subscriptions are experimental in Centrifugo, and the module follows their changes.
tokentoken
Tokens: the connection and subscription tokens Centrifugo authenticates clients with, the server API tokens of Centrifugo PRO, and JWKS.

Structs§

ApiError
An error Centrifugo returned: it understood the request, and refused it or failed to carry it out. It is the same whether Centrifugo puts it in a 200 reply or, in its transport error mode, in the body of an HTTP error status.
ApnsPushNotification
ApnsPushNotification is a notification for APNs. Centrifugo PRO only.
AutoBatchclient
Lets the client send concurrent calls together, as one batch request, once enough of them are in flight. Off unless set.
Backoffclient
The wait before retrying, growing exponentially with the attempt: see exponential_backoff.
Batchclient
Commands sent to Centrifugo in one request. Create one with Client::new_batch, add commands with its methods - one per API method, such as Batch::publish - then send it:
BatchFailedCommandsErrorclient
A batch in which one or more commands failed, up to all of them. Every command got its own reply: each one’s outcome, success or failure, is in its Pending.
BatchOptionsclient
How Centrifugo runs a batch. The options are set when the batch is created, since they change what its commands mean together: in what order they take effect.
BatchResultclient
The outcome of a sent batch as a whole: each command’s own result is in the Pending its method returned. Encoded as JSON, it gives the failed commands with their errors.
BlockUserRequest
BlockUserRequest blocks a user: the user is disconnected and can not connect again until unblocked or the block expires. Centrifugo PRO only.
BlockUserResult
BlockUserResult is the result of a block user call. Empty at the moment. Centrifugo PRO only.
BroadcastAttemptclient
A failed attempt of Client::broadcast_with_retry, for its on_attempt_error callback.
BroadcastFailedChannelsError
A broadcast which Centrifugo carried out, and which failed in one or more of its channels, up to all of them: the others got the publication.
BroadcastRequest
BroadcastRequest publishes the same data into many channels.
BroadcastResult
The outcome of a broadcast: one entry per channel, in the order the request listed them.
BroadcastRetryOptionsclient
How Client::broadcast_with_retry retries. The default retries once, after a wait of about 100 milliseconds.
CancelPushRequest
CancelPushRequest cancels a delayed push notification (sent with send_at). Centrifugo PRO only.
CancelPushResult
CancelPushResult is the result of a cancel push call. Empty at the moment. Centrifugo PRO only.
ChannelContext
ChannelContext is context of a channel subscription. Centrifugo PRO only.
ChannelInfo
ChannelInfo is information about an active channel.
ChannelResult
The outcome of a broadcast in one channel.
ChannelsRequest
ChannelsRequest returns active channels (with one or more subscribers). It can be heavy on large deployments: there is no pagination.
ChannelsResult
ChannelsResult is the result of a channels call.
Clientclient
Calls Centrifugo’s HTTP server API: a method per API method, taking its request and returning its result.
ClientInfo
ClientInfo describes a client connection.
Command
An API call left for Centrifugo’s async consumers to make, instead of calling Centrifugo: written to a PostgreSQL outbox table, a Kafka topic, a Redis stream. A function per API method makes one, such as Command::publish: it checks the request as the client does before sending it - an invalid request fails here, rather than in a consumer, which drops a command it cannot run - and encodes it.
Configclient
Configures a Client. Client::new checks it, and reports every mistake it can see before any request is made.
ConnectionInfo
ConnectionInfo is information about a client connection. Centrifugo PRO only.
ConnectionState
ConnectionState is the state of a client connection. Centrifugo PRO only.
ConnectionTokenInfo
ConnectionTokenInfo is information about a connection token. Centrifugo PRO only.
ConnectionsRequest
ConnectionsRequest returns information about active connections, without the need to enable presence. At least one of user, expression or label_filter must be set. Centrifugo PRO only.
ConnectionsResult
ConnectionsResult is the result of a connections call. Centrifugo PRO only.
DecodeError
A reply which is not Centrifugo’s: usually an api_endpoint which does not point at Centrifugo’s API, so that something else answers instead.
DefaultHttpClientclient
The HTTP client a Client uses unless given another: hyper with rustls, verifying certificates with the operating system’s trust store.
DeleteUserStatusRequest
DeleteUserStatusRequest deletes the status of users. Centrifugo PRO only.
DeleteUserStatusResult
DeleteUserStatusResult is the result of a delete user status call. Empty at the moment. Centrifugo PRO only.
Device
Device is a device registered for push notifications. Centrifugo PRO only.
DeviceFilter
DeviceFilter selects devices. Centrifugo PRO only.
DeviceListRequest
DeviceListRequest returns a paginated list of registered devices. Centrifugo PRO only.
DeviceListResult
DeviceListResult is the result of a device list call. Centrifugo PRO only.
DeviceLocaleUpdate
DeviceLocaleUpdate sets the locale of devices. Centrifugo PRO only.
DeviceMetaUpdate
DeviceMetaUpdate sets the meta of devices. Centrifugo PRO only.
DeviceRegisterRequest
DeviceRegisterRequest registers a device for push notifications, or updates a registered one. Centrifugo PRO only.
DeviceRegisterResult
DeviceRegisterResult is the result of a device register call. Centrifugo PRO only.
DeviceRemoveRequest
DeviceRemoveRequest removes devices, selected by ids and/or users. Centrifugo PRO only.
DeviceRemoveResult
DeviceRemoveResult is the result of a device remove call. Empty at the moment. Centrifugo PRO only.
DeviceTimezoneUpdate
DeviceTimezoneUpdate sets the timezone of devices. Centrifugo PRO only.
DeviceTopic
DeviceTopic is a topic subscription of a device. Centrifugo PRO only.
DeviceTopicFilter
DeviceTopicFilter selects device topic subscriptions. Centrifugo PRO only.
DeviceTopicListRequest
DeviceTopicListRequest returns a paginated list of device topic subscriptions. Centrifugo PRO only.
DeviceTopicListResult
DeviceTopicListResult is the result of a device topic list call. Centrifugo PRO only.
DeviceTopicUpdateRequest
DeviceTopicUpdateRequest changes the topics of a device. The device topic list is what decides who gets a push sent to a topic. Centrifugo PRO only.
DeviceTopicUpdateResult
DeviceTopicUpdateResult is the result of a device topic update call. Empty at the moment. Centrifugo PRO only.
DeviceTopicsUpdate
DeviceTopicsUpdate changes the topics of devices. Centrifugo PRO only.
DeviceUpdateRequest
DeviceUpdateRequest updates registered devices, selected by ids and/or users. Centrifugo PRO only.
DeviceUpdateResult
DeviceUpdateResult is the result of a device update call. Empty at the moment. Centrifugo PRO only.
DeviceUserUpdate
DeviceUserUpdate sets the user of devices. Centrifugo PRO only.
Disconnect
Disconnect describes the code and reason clients are disconnected with.
DisconnectRequest
DisconnectRequest disconnects a user’s connections.
DisconnectResult
DisconnectResult is the result of a disconnect call. Empty at the moment.
FailedCommandclient
The failure of one command of a batch.
FcmPushNotification
FcmPushNotification is a notification for FCM. Centrifugo PRO only.
FilterNode
FilterNode is a tree describing a predicate over client labels. Used as label_filter on Subscribe, Unsubscribe, Disconnect, Refresh and Connections requests. A node is either a leaf comparison (key, cmp, val or vals) or a logical operation (op) over child nodes. Centrifugo PRO only: defined here for protocol-surface consistency, Centrifugo OSS parses it but ignores it.
FunctionError
An error of the application’s function given to Config::with_endpoint_fn or Config::bearer_token: the function’s own error, its source, and the function’s name.
GetUserStatusRequest
GetUserStatusRequest returns the status of users. Centrifugo PRO only.
GetUserStatusResult
GetUserStatusResult is the result of a get user status call. Centrifugo PRO only.
Handler
An HTTP endpoint: a proxy handler, an endpoint client SDKs call, or a JWKS endpoint. It is one function, handle, from a request with its whole body to a response, holding all of the endpoint’s behaviour - statuses, headers, body limits - so that it serves from any framework:
HistoryItem
A publication read by history_all, with the epoch of the stream it was read from: its position is where to resume reading, or the recover_since of a subscription, with no fields copied by hand (spec 3.8). It derefs to the Publication: item.offset, item.data.
HistoryRemoveRequest
HistoryRemoveRequest removes publications from the history of a channel. The current top stream position is kept, so clients do not get disconnected because of insufficient state.
HistoryRemoveResult
HistoryRemoveResult is the result of a history remove call. Empty at the moment.
HistoryRequest
HistoryRequest returns publications from the history of a channel. History must be enabled for the channel.
HistoryResult
HistoryResult is the result of a history call.
HmsPushNotification
HmsPushNotification is a notification for HMS. Centrifugo PRO only.
HttpError
A reply with an HTTP status other than 200 OK: the request did not reach the API method at all.
InfoRequest
InfoRequest returns information about the running Centrifugo nodes.
InfoResult
InfoResult is the result of an info call.
InvalidConfigError
A client not created - or used where it cannot work - with a message naming the option and the fix.
InvalidRequestError
A request the client did not send, because it could tell it is wrong: a publication without a channel or data, say. Only rules which hold for every Centrifugo are checked; everything else is Centrifugo’s to check.
InvalidateUserTokensRequest
InvalidateUserTokensRequest revokes all tokens of a user issued before a certain time (based on the iat claim of a JWT). Centrifugo PRO only.
InvalidateUserTokensResult
InvalidateUserTokensResult is the result of an invalidate user tokens call. Empty at the moment. Centrifugo PRO only.
MapClearRequest
MapClearRequest removes all state and stream data of a map channel.
MapClearResult
MapClearResult is the result of a map clear call. Empty at the moment.
MapEntry
MapEntry is an entry of a map channel state or stream.
MapPublishRequest
MapPublishRequest publishes or updates a key in a map channel.
MapPublishResult
MapPublishResult is the result of a map publish call.
MapReadStateRequest
MapReadStateRequest reads the current state of a map channel, with optional pagination.
MapReadStateResult
MapReadStateResult is the result of a map read state call.
MapReadStreamRequest
MapReadStreamRequest reads the change stream of a map channel.
MapReadStreamResult
MapReadStreamResult is the result of a map read stream call.
MapRemoveRequest
MapRemoveRequest removes a key from a map channel.
MapRemoveResult
MapRemoveResult is the result of a map remove call.
MapStateItem
An entry read by map_read_state_all, with the position of the state it was read at: reading the map’s stream from state with map_read_stream gets every change made since (spec 3.8). It derefs to the MapEntry: item.key, item.data.
MapStatsRequest
MapStatsRequest returns statistics about a map channel.
MapStatsResult
MapStatsResult is the result of a map stats call.
Metrics
Metrics are aggregated metrics of a node.
NetworkError
A failure of the network: connecting, TLS, the connection breaking.
NodeResult
NodeResult is information about a Centrifugo node.
Pagerclient
The items of a paged method, every page of them, read a page at a time: what Client::history_all, Client::device_list_all and the other *_all methods return.
PayloadError
A payload which did not encode, or decode as the type asked.
Pendingclient
The outcome of one command of a Batch, available once the batch is sent.
PresenceRequest
PresenceRequest returns the online presence of a channel: all clients currently subscribed to it. Presence must be enabled for the channel.
PresenceResult
PresenceResult is the result of a presence call.
PresenceStatsRequest
PresenceStatsRequest returns short presence information of a channel: the number of clients and of unique users. Presence must be enabled for the channel.
PresenceStatsResult
PresenceStatsResult is the result of a presence stats call.
Process
Process is resource usage of a node process. Centrifugo PRO only.
Publication
Publication is a publication in a channel history.
PublishRequest
PublishRequest publishes data into a channel.
PublishResult
PublishResult is the result of a successful publish.
PushLimitStrategy
PushLimitStrategy limits when and how often pushes are sent. Centrifugo PRO only.
PushLocalization
PushLocalization holds translations for one language/locale. Centrifugo PRO only.
PushNotification
PushNotification is a push notification in the format of each provider. Centrifugo PRO only.
PushRateLimitStrategy
PushRateLimitStrategy rate limits pushes per device. Centrifugo PRO only.
PushRecipient
PushRecipient describes who receives a push notification. Set only one of its fields. Centrifugo PRO only.
PushTimeLimitStrategy
PushTimeLimitStrategy sends pushes within a window of the device local time. Centrifugo PRO only.
RateLimitPolicy
RateLimitPolicy allows rate pushes per interval_ms. Centrifugo PRO only.
RawValue
Reference to a range of bytes encompassing a single valid JSON value in the input data.
RefreshRequest
RefreshRequest refreshes a user’s connections, mostly useful with unidirectional transports. Without expire_at the connections become non-expiring.
RefreshResult
RefreshResult is the result of a refresh call. Empty at the moment.
RequestInfoclient
Describes one HTTP request to the API, for Config::on_request.
RetryStoppedError
A broadcast with retries which stopped before its last attempt: its on_attempt_error callback returned an error, or the call’s deadline came while it waited to retry. error is the broadcast’s error at that point - a Error::BroadcastFailedChannels holding every channel’s outcome when some attempt got a reply.
RevokeTokenRequest
RevokeTokenRequest revokes a token by its unique ID (jti claim of a JWT). Clients using the token are disconnected shortly, and can not connect with it again. Centrifugo PRO only.
RevokeTokenResult
RevokeTokenResult is the result of a revoke token call. Empty at the moment. Centrifugo PRO only.
SendPushNotificationRequest
SendPushNotificationRequest sends a push notification. The request is queued and sent to the provider by Centrifugo workers. Centrifugo PRO only.
SendPushNotificationResult
SendPushNotificationResult is the result of a send push notification call. Centrifugo PRO only.
SharedPollPublishRequest
SharedPollPublishRequest pushes data for a key directly to clients of a shared poll channel, without waiting for the next poll cycle. Requires versioned mode and publish_enabled on the namespace.
SharedPollPublishResult
SharedPollPublishResult is the result of a shared poll publish call. Empty at the moment.
StreamPosition
StreamPosition is a position in a channel stream.
SubscribeOptionOverride
SubscribeOptionOverride overrides channel options for a server-side subscription. Unset fields keep the value from the channel configuration.
SubscribeRequest
SubscribeRequest subscribes active sessions of a user to a channel (server-side subscription). It does not create a streaming subscription for the caller.
SubscribeResult
SubscribeResult is the result of a subscribe call. Empty at the moment.
SubscriptionTokenInfo
SubscriptionTokenInfo is information about a subscription token. Centrifugo PRO only.
TimeoutError
A call whose deadline passed. After a timeout Centrifugo may still have carried the request out: retry a publication only with the same idempotency_key.
UnblockUserRequest
UnblockUserRequest unblocks a user. Centrifugo PRO only.
UnblockUserResult
UnblockUserResult is the result of an unblock user call. Empty at the moment. Centrifugo PRO only.
UnsubscribeRequest
UnsubscribeRequest unsubscribes a user from a channel.
UnsubscribeResult
UnsubscribeResult is the result of an unsubscribe call. Empty at the moment.
UpdatePushStatusRequest
UpdatePushStatusRequest saves the delivery or interaction status of a push notification to analytics. Experimental. Centrifugo PRO only.
UpdatePushStatusResult
UpdatePushStatusResult is the result of an update push status call. Empty at the moment. Centrifugo PRO only.
UpdateUserStatusRequest
UpdateUserStatusRequest marks users as active and online now, and sets their state when one is given. Centrifugo PRO only.
UpdateUserStatusResult
UpdateUserStatusResult is the result of an update user status call. Empty at the moment. Centrifugo PRO only.
UserStatus
UserStatus is the status of a user. Centrifugo PRO only.
UserTopic
UserTopic is a topic subscription of a user. Centrifugo PRO only.
UserTopicFilter
UserTopicFilter selects user topic subscriptions. Centrifugo PRO only.
UserTopicListRequest
UserTopicListRequest returns a paginated list of user topic subscriptions. Centrifugo PRO only.
UserTopicListResult
UserTopicListResult is the result of a user topic list call. Centrifugo PRO only.
UserTopicUpdateRequest
UserTopicUpdateRequest changes the topics of a user. The change is also applied to the user’s registered devices. Centrifugo PRO only.
UserTopicUpdateResult
UserTopicUpdateResult is the result of a user topic update call. Empty at the moment. Centrifugo PRO only.
WebPushPushNotification
WebPushPushNotification is a notification for Web Push. Centrifugo PRO only.

Enums§

Error
The error of a call. Every call returns one unless it did everything it was asked: ? is always correct code.
Retryclient
What Client::broadcast_with_retry does after a failed attempt, as its on_attempt_error callback decides.

Constants§

CMP_CT
"ct", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_EQ
"eq", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_EW
"ew", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_EX
"ex", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_GT
"gt", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_GTE
"gte", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_IN
"in", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_LT
"lt", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_LTE
"lte", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_NEQ
"neq", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_NEX
"nex", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_NIN
"nin", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
CMP_SW
"sw", a value of cmp of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
FILTER_NODE_OP_AND
"and", a value of op of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
FILTER_NODE_OP_NOT
"not", a value of op of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
FILTER_NODE_OP_OR
"or", a value of op of FilterNode. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
KEY_MODE_IF_EXISTS
"if_exists", a value of key_mode of MapPublishRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
KEY_MODE_IF_NEW
"if_new", a value of key_mode of MapPublishRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
OP_ADD
"add", a value of op of DeviceTopicsUpdate, op of DeviceTopicUpdateRequest and op of UserTopicUpdateRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
OP_REMOVE
"remove", a value of op of DeviceTopicsUpdate, op of DeviceTopicUpdateRequest and op of UserTopicUpdateRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
OP_SET
"set", a value of op of DeviceTopicsUpdate, op of DeviceTopicUpdateRequest and op of UserTopicUpdateRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
PLATFORM_ANDROID
"android", a value of platform of DeviceRegisterRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
PLATFORM_IOS
"ios", a value of platform of DeviceRegisterRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
PLATFORM_WEB
"web", a value of platform of DeviceRegisterRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
PROVIDER_APNS
"apns", a value of provider of DeviceRegisterRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
PROVIDER_FCM
"fcm", a value of provider of DeviceRegisterRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
PROVIDER_HMS
"hms", a value of provider of DeviceRegisterRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
PROVIDER_WEBPUSH
"webpush", a value of provider of DeviceRegisterRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
STATUS_DELIVERED
"delivered", a value of status of UpdatePushStatusRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.
STATUS_INTERACTED
"interacted", a value of status of UpdatePushStatusRequest. The field is a string: a value Centrifugo accepts which no constant names can still be sent.

Traits§

EndpointSourceclient
Returns Centrifugo’s base URL per request: see Config::with_endpoint_fn. A closure returning a future of Result<String, BoxError> is one.
HttpClientclient
Sends the client’s HTTP requests: DefaultHttpClient, or one of the application’s - to add tracing, to test code using the client without Centrifugo.
PayloadExt
Decodes a payload into an application type: a publication’s data, a proxy request’s data, a presence entry’s conn_info.
Request
Implemented by the request type of every API method: PublishRequest, BroadcastRequest and the others. Only the crate’s types implement it.
TokenSourceclient
Returns the token sent with every request as Authorization: Bearer, for Centrifugo PRO’s JWKS authentication of the API: see Config::bearer_token. A closure returning a future of Result<String, BoxError> is one, and so is token::ApiTokenSource.

Functions§

exponential_backoffclient
Returns the wait before retrying after a failed attempt, with attempt 1 being the first failure: base after it, twice as long after each next one, up to limit. Each wait is a random time between half of it and all of it, so that clients which failed together - when a broker was down - do not all retry at the same moment. A limit below base counts as base, and an attempt below 1 as 1.
json
Encodes value as a payload, for the data, info and other payload fields of requests and proxy results:
retryable
Reports whether retrying the call which returned err may succeed: the error came from a temporary condition, not from the request.
waitclient
Waits for d, or until deadline, and returns Error::Timeout when the deadline comes first: the wait between the attempts of a retry loop sharing a deadline. A sleep which ignores the deadline would keep the loop - and Client::close - waiting after it.

Type Aliases§

BoxError
A boxed error, as application functions return them: the endpoint and token functions, HTTP clients, handler functions.
BoxFutureclient
A boxed future, as the traits of the crate return them.
OnAttemptErrorclient
Decides what happens after a failed attempt of Client::broadcast_with_retry: see BroadcastRetryOptions::on_attempt_error.