Skip to main content

Subscriber

Struct Subscriber 

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

Subscriber - 负责订阅任务事件和通知 Subscriber - responsible for subscribing to task events and notifications

对应 Go asynq 的 subscriber 组件 Corresponds to Go asynq’s subscriber component

Subscriber 允许应用程序订阅任务生命周期事件,用于监控、日志记录或触发其他操作。 Subscriber allows applications to subscribe to task components events for monitoring, logging, or triggering other actions.

Implementations§

Source§

impl Subscriber

Source

pub fn new(broker: Arc<dyn Broker>, config: SubscriberConfig) -> Self

创建新的 Subscriber Create a new Subscriber

Source

pub fn take_receiver(&mut self) -> Option<Receiver<SubscriptionEvent>>

获取事件接收器 Get event receiver

调用此方法后,接收器的所有权将转移,后续调用将返回 None After calling this method, ownership of the receiver is transferred, subsequent calls will return None

Source

pub fn start(self: Arc<Self>) -> JoinHandle<()>

启动 Subscriber Start the Subscriber

对应 Go 的 subscriber.start() Corresponds to Go’s subscriber.start()

Source

pub async fn publish(&self, event: SubscriptionEvent) -> Result<()>

发布事件 Publish event

此方法允许其他组件发布事件到订阅者 This method allows other components to publish events to subscribers

Source

pub fn shutdown(&self)

停止 Subscriber Stop the Subscriber

对应 Go 的 subscriber.shutdown() Corresponds to Go’s subscriber.shutdown()

Source

pub fn is_done(&self) -> bool

检查是否已完成 Check if done

Trait Implementations§

Source§

impl ComponentLifecycle for Subscriber

Source§

fn start(self: Arc<Self>) -> JoinHandle<()>

启动组件 Start the component Read more
Source§

fn shutdown(&self)

关闭组件 Shutdown the component Read more
Source§

fn is_done(&self) -> bool

检查组件是否已完成 Check if the component is done 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> 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, 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<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