Skip to main content

Gateway

Struct Gateway 

Source
pub struct Gateway { /* private fields */ }
Expand description

Gateway API 客户端 — 对齐 PHP GatewayWorker\Gateway

提供 WebSocket 客户端管理、群组广播、消息推送等能力。 通过 GatewayTransport trait 抽象底层通信。

§PHP 对齐

PHP Gateway 全部为静态方法,Rust 通过实例方法表达,配置与传输层通过构造函数注入, 便于测试和多实例隔离。

§用法

use sz_rust_auth_facade::gateway::{
    Gateway, GatewayConfig, MemoryGatewayTransport, GatewayTransport,
};
use std::sync::Arc;

let transport = Arc::new(MemoryGatewayTransport::new());
let gateway = Gateway::new(GatewayConfig::new("127.0.0.1:1238"), transport.clone());

transport.register_client("7f00000108fc00000001");
gateway.send_to_client("7f00000108fc00000001", "hello").unwrap();

Implementations§

Source§

impl Gateway

Source

pub fn new( config: GatewayConfig, transport: Arc<dyn GatewayTransport>, ) -> Gateway

创建 Gateway 客户端

§参数
  • config: Gateway 配置
  • transport: 传输层实现(业务方注入 Redis pub/sub / HTTP / TCP 等具体实现)
Source

pub fn send_to_client( &self, client_id: &str, message: &str, ) -> Result<(), GatewayError>

向指定 client_id 发送消息 — 对齐 Gateway::sendToClient()

Source

pub fn send_to_all(&self, message: &str) -> Result<(), GatewayError>

向所有在线 client_id 发送广播 — 对齐 Gateway::sendToAll()

Source

pub fn send_to_group( &self, group: &str, message: &str, ) -> Result<(), GatewayError>

向指定群组发送消息 — 对齐 Gateway::sendToGroup()

Source

pub fn join_group( &self, client_id: &str, group: &str, ) -> Result<(), GatewayError>

将 client_id 加入群组 — 对齐 Gateway::joinGroup()

Source

pub fn leave_group( &self, client_id: &str, group: &str, ) -> Result<(), GatewayError>

将 client_id 离开群组 — 对齐 Gateway::leaveGroup()

Source

pub fn ungroup(&self, group: &str) -> Result<(), GatewayError>

解散指定群组 — 对齐 Gateway::ungroup()

Source

pub fn is_online(&self, client_id: &str) -> Result<bool, GatewayError>

判断 client_id 是否在线 — 对齐 Gateway::isOnline()

Source

pub fn get_client_count(&self) -> Result<usize, GatewayError>

获取在线 client_id 数量 — 对齐 Gateway::getClientCount()

Source

pub fn get_client_count_by_group( &self, group: &str, ) -> Result<usize, GatewayError>

获取指定群组的在线 client_id 数量 — 对齐 Gateway::getClientCountByGroup()

Source

pub fn get_all_client_ids(&self) -> Result<Vec<String>, GatewayError>

获取所有在线 client_id — 对齐 Gateway::getAllClientIds()

Source

pub fn get_client_id_list_by_group( &self, group: &str, ) -> Result<Vec<String>, GatewayError>

获取指定群组中的 client_id — 对齐 Gateway::getClientIdListByGroup()

Source

pub fn close_client(&self, client_id: &str) -> Result<(), GatewayError>

关闭指定 client_id 的连接 — 对齐 Gateway::closeClient()

Source

pub fn config(&self) -> &GatewayConfig

获取 Gateway 配置

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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