pub struct Command { /* private fields */ }Expand description
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.
Consumers take a command in one of two forms:
- its
methodandpayloadapart: the outbox table’smethodandpayloadcolumns, or a payload with the method in a message attribute (Google Cloud Pub/Sub, AWS SQS, Azure Service Bus, a Redis stream); - the command encoded as JSON,
{"method": ..., "payload": {...}}, as the message itself (Kafka, NATS JetStream):to_json, or the command serialized with serde, which gives the payload as the JSON object, never as a string of it.
Where the method comes apart from the payload, Centrifugo reads the
payload as the request itself: write it as the JSON object - a jsonb
column, a message body - never as a string of it, which a consumer drops
with only Centrifugo’s log saying so.
let data = cent::json(&serde_json::json!({"text": "hi"}))?;
let cmd = cent::Command::publish(cent::PublishRequest::new("news").data(data))?;
// INSERT INTO centrifugo_outbox (method, payload, partition) VALUES ($1, $2::jsonb, $3)
assert_eq!(cmd.method(), "publish");
assert_eq!(cmd.payload().get(), r#"{"channel":"news","data":{"text":"hi"}}"#);Within a partition - an outbox table’s partition, a Kafka partition - a consumer runs commands in order; across partitions it does not. To keep a channel’s commands in order, write them to one partition, derived from the channel the same way by every writer: the channel as a Kafka message key, say, or a hash of it modulo the outbox table’s number of partitions.
Implementations§
Source§impl Command
impl Command
Sourcepub fn publish(request: PublishRequest) -> Result<Self, Error>
pub fn publish(request: PublishRequest) -> Result<Self, Error>
The publish command: what Client::publish would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn broadcast(request: BroadcastRequest) -> Result<Self, Error>
pub fn broadcast(request: BroadcastRequest) -> Result<Self, Error>
The broadcast command: what Client::broadcast would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn subscribe(request: SubscribeRequest) -> Result<Self, Error>
pub fn subscribe(request: SubscribeRequest) -> Result<Self, Error>
The subscribe command: what Client::subscribe would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn unsubscribe(request: UnsubscribeRequest) -> Result<Self, Error>
pub fn unsubscribe(request: UnsubscribeRequest) -> Result<Self, Error>
The unsubscribe command: what Client::unsubscribe would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn disconnect(request: DisconnectRequest) -> Result<Self, Error>
pub fn disconnect(request: DisconnectRequest) -> Result<Self, Error>
The disconnect command: what Client::disconnect would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn presence(request: PresenceRequest) -> Result<Self, Error>
pub fn presence(request: PresenceRequest) -> Result<Self, Error>
The presence command: what Client::presence would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn presence_stats(request: PresenceStatsRequest) -> Result<Self, Error>
pub fn presence_stats(request: PresenceStatsRequest) -> Result<Self, Error>
The presence_stats command: what Client::presence_stats would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn history(request: HistoryRequest) -> Result<Self, Error>
pub fn history(request: HistoryRequest) -> Result<Self, Error>
The history command: what Client::history would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn history_remove(request: HistoryRemoveRequest) -> Result<Self, Error>
pub fn history_remove(request: HistoryRemoveRequest) -> Result<Self, Error>
The history_remove command: what Client::history_remove would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn info(request: InfoRequest) -> Result<Self, Error>
pub fn info(request: InfoRequest) -> Result<Self, Error>
The info command: what Client::info would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn refresh(request: RefreshRequest) -> Result<Self, Error>
pub fn refresh(request: RefreshRequest) -> Result<Self, Error>
The refresh command: what Client::refresh would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn channels(request: ChannelsRequest) -> Result<Self, Error>
pub fn channels(request: ChannelsRequest) -> Result<Self, Error>
The channels command: what Client::channels would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn connections(request: ConnectionsRequest) -> Result<Self, Error>
pub fn connections(request: ConnectionsRequest) -> Result<Self, Error>
The connections command: what Client::connections would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn update_user_status(
request: UpdateUserStatusRequest,
) -> Result<Self, Error>
pub fn update_user_status( request: UpdateUserStatusRequest, ) -> Result<Self, Error>
The update_user_status command: what Client::update_user_status would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn get_user_status(request: GetUserStatusRequest) -> Result<Self, Error>
pub fn get_user_status(request: GetUserStatusRequest) -> Result<Self, Error>
The get_user_status command: what Client::get_user_status would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn delete_user_status(
request: DeleteUserStatusRequest,
) -> Result<Self, Error>
pub fn delete_user_status( request: DeleteUserStatusRequest, ) -> Result<Self, Error>
The delete_user_status command: what Client::delete_user_status would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn block_user(request: BlockUserRequest) -> Result<Self, Error>
pub fn block_user(request: BlockUserRequest) -> Result<Self, Error>
The block_user command: what Client::block_user would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn unblock_user(request: UnblockUserRequest) -> Result<Self, Error>
pub fn unblock_user(request: UnblockUserRequest) -> Result<Self, Error>
The unblock_user command: what Client::unblock_user would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn revoke_token(request: RevokeTokenRequest) -> Result<Self, Error>
pub fn revoke_token(request: RevokeTokenRequest) -> Result<Self, Error>
The revoke_token command: what Client::revoke_token would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn invalidate_user_tokens(
request: InvalidateUserTokensRequest,
) -> Result<Self, Error>
pub fn invalidate_user_tokens( request: InvalidateUserTokensRequest, ) -> Result<Self, Error>
The invalidate_user_tokens command: what Client::invalidate_user_tokens would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn device_register(request: DeviceRegisterRequest) -> Result<Self, Error>
pub fn device_register(request: DeviceRegisterRequest) -> Result<Self, Error>
The device_register command: what Client::device_register would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn device_update(request: DeviceUpdateRequest) -> Result<Self, Error>
pub fn device_update(request: DeviceUpdateRequest) -> Result<Self, Error>
The device_update command: what Client::device_update would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn device_remove(request: DeviceRemoveRequest) -> Result<Self, Error>
pub fn device_remove(request: DeviceRemoveRequest) -> Result<Self, Error>
The device_remove command: what Client::device_remove would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn device_list(request: DeviceListRequest) -> Result<Self, Error>
pub fn device_list(request: DeviceListRequest) -> Result<Self, Error>
The device_list command: what Client::device_list would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn device_topic_list(request: DeviceTopicListRequest) -> Result<Self, Error>
pub fn device_topic_list(request: DeviceTopicListRequest) -> Result<Self, Error>
The device_topic_list command: what Client::device_topic_list would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn device_topic_update(
request: DeviceTopicUpdateRequest,
) -> Result<Self, Error>
pub fn device_topic_update( request: DeviceTopicUpdateRequest, ) -> Result<Self, Error>
The device_topic_update command: what Client::device_topic_update would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn user_topic_list(request: UserTopicListRequest) -> Result<Self, Error>
pub fn user_topic_list(request: UserTopicListRequest) -> Result<Self, Error>
The user_topic_list command: what Client::user_topic_list would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn user_topic_update(request: UserTopicUpdateRequest) -> Result<Self, Error>
pub fn user_topic_update(request: UserTopicUpdateRequest) -> Result<Self, Error>
The user_topic_update command: what Client::user_topic_update would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn send_push_notification(
request: SendPushNotificationRequest,
) -> Result<Self, Error>
pub fn send_push_notification( request: SendPushNotificationRequest, ) -> Result<Self, Error>
The send_push_notification command: what Client::send_push_notification would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn update_push_status(
request: UpdatePushStatusRequest,
) -> Result<Self, Error>
pub fn update_push_status( request: UpdatePushStatusRequest, ) -> Result<Self, Error>
The update_push_status command: what Client::update_push_status would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn cancel_push(request: CancelPushRequest) -> Result<Self, Error>
pub fn cancel_push(request: CancelPushRequest) -> Result<Self, Error>
The cancel_push command: what Client::cancel_push would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn map_publish(request: MapPublishRequest) -> Result<Self, Error>
pub fn map_publish(request: MapPublishRequest) -> Result<Self, Error>
The map_publish command: what Client::map_publish would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn map_remove(request: MapRemoveRequest) -> Result<Self, Error>
pub fn map_remove(request: MapRemoveRequest) -> Result<Self, Error>
The map_remove command: what Client::map_remove would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn map_read_state(request: MapReadStateRequest) -> Result<Self, Error>
pub fn map_read_state(request: MapReadStateRequest) -> Result<Self, Error>
The map_read_state command: what Client::map_read_state would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn map_read_stream(request: MapReadStreamRequest) -> Result<Self, Error>
pub fn map_read_stream(request: MapReadStreamRequest) -> Result<Self, Error>
The map_read_stream command: what Client::map_read_stream would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn map_stats(request: MapStatsRequest) -> Result<Self, Error>
pub fn map_stats(request: MapStatsRequest) -> Result<Self, Error>
The map_stats command: what Client::map_stats would send, checked
as the client checks it, for Centrifugo’s async consumers.
Sourcepub fn map_clear(request: MapClearRequest) -> Result<Self, Error>
pub fn map_clear(request: MapClearRequest) -> Result<Self, Error>
The map_clear command: what Client::map_clear would send, checked
as the client checks it, for Centrifugo’s async consumers.
The shared_poll_publish command: what Client::shared_poll_publish would send, checked
as the client checks it, for Centrifugo’s async consumers.