Skip to main content

ObserverServerBuilder

Struct ObserverServerBuilder 

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

观察者模式服务端构建器

提供基本功能实现,使用 ServerEventHandler trait 处理消息和事件。

§设计原则

  • 公共逻辑统一处理:基于 HybridServer,共享所有核心能力
  • 自动消息路由ServerMessageWrapper 自动将消息路由到 ServerEventHandler 的对应方法
  • 自动 ACK 处理:如果 handler 返回 None,框架自动发送 ACK
  • 错误处理:处理失败时自动发送错误 ACK,确保客户端能收到响应

§使用方式

用户只需要实现 ServerEventHandler trait,框架会自动处理消息路由和 ACK。

Implementations§

Source§

impl ObserverServerBuilder

Source

pub fn new( bind_address: impl Into<String>, event_handler: Arc<dyn ServerEventHandler>, ) -> Self

创建新的观察者模式构建器

§参数
  • bind_address: 绑定地址
  • event_handler: 事件处理器(必须),用户只需要实现 ServerEventHandlerhandle_message 方法即可
Source

pub fn with_authenticator(self, authenticator: Arc<dyn Authenticator>) -> Self

设置认证器(如果启用认证,必须提供)

如果设置了认证器,还需要在配置中启用认证:

.enable_auth()
.with_authenticator(authenticator)
Source

pub fn enable_auth(self) -> Self

启用认证

Source

pub fn with_auth_timeout(self, timeout: Duration) -> Self

设置认证超时时间

Source

pub fn with_device_manager(self, device_manager: Arc<DeviceManager>) -> Self

设置设备管理器(用于设备冲突管理)

Source

pub fn with_connection_manager(self, manager: Arc<ConnectionManager>) -> Self

设置连接管理器(可选,用于共享连接状态)

Source

pub fn with_protocol(self, protocol: TransportProtocol) -> Self

设置传输协议

Source

pub fn with_protocols(self, protocols: Vec<TransportProtocol>) -> Self

启用多协议监听

Source

pub fn with_protocol_address( self, protocol: TransportProtocol, address: String, ) -> Self

为特定协议设置监听地址

Source

pub fn with_max_connections(self, max: usize) -> Self

设置最大连接数

Source

pub fn with_handshake_timeout(self, timeout: Duration) -> Self

设置握手超时时间

Source

pub fn with_max_handshake_concurrency(self, max: usize) -> Self

设置最大并发握手数

Source

pub fn with_write_timeout(self, timeout: Duration) -> Self

设置单次连接写入超时时间

Source

pub fn with_fanout_concurrency(self, max: usize) -> Self

设置 fanout 发送最大并发度

Source

pub fn with_heartbeat(self, heartbeat: HeartbeatConfig) -> Self

设置心跳配置

Source

pub fn with_tls(self, tls: TlsConfig) -> Self

设置 TLS 配置

Source

pub fn with_default_format(self, format: SerializationFormat) -> Self

设置默认序列化格式(用于协商,默认 Protobuf)

Source

pub fn with_default_compression(self, compression: CompressionAlgorithm) -> Self

设置默认压缩算法(用于协商,默认 None)

Source

pub fn build(self) -> Result<ObserverServer>

构建服务端

§错误处理
  • 如果配置无效(如启用了认证但未提供认证器),返回配置错误
  • 如果服务器初始化失败,返回相应的错误
§返回
  • Ok(ObserverServer) - 成功构建的服务端实例
  • Err(FlareError) - 构建失败的错误信息

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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

Source§

type Output = T

Should always be Self
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