Skip to main content

Command

Struct Command 

Source
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 method and payload apart: the outbox table’s method and payload columns, 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

Source

pub fn method(&self) -> &'static str

The API method, such as "publish".

Source

pub fn payload(&self) -> &RawValue

The request, as JSON: for a jsonb column, write payload().get().

Source

pub fn to_json(&self) -> String

The command as a JSON message: {"method": ..., "payload": {...}}.

Source§

impl Command

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn shared_poll_publish( request: SharedPollPublishRequest, ) -> Result<Self, Error>

The shared_poll_publish command: what Client::shared_poll_publish would send, checked as the client checks it, for Centrifugo’s async consumers.

Trait Implementations§

Source§

impl Clone for Command

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Command

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Command

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more