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
impl Subscriber
Sourcepub fn new(broker: Arc<dyn Broker>, config: SubscriberConfig) -> Self
pub fn new(broker: Arc<dyn Broker>, config: SubscriberConfig) -> Self
创建新的 Subscriber Create a new Subscriber
Sourcepub fn take_receiver(&mut self) -> Option<Receiver<SubscriptionEvent>>
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
Sourcepub fn start(self: Arc<Self>) -> JoinHandle<()>
pub fn start(self: Arc<Self>) -> JoinHandle<()>
启动 Subscriber Start the Subscriber
对应 Go 的 subscriber.start() Corresponds to Go’s subscriber.start()
Sourcepub async fn publish(&self, event: SubscriptionEvent) -> Result<()>
pub async fn publish(&self, event: SubscriptionEvent) -> Result<()>
发布事件 Publish event
此方法允许其他组件发布事件到订阅者 This method allows other components to publish events to subscribers
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Subscriber
impl !RefUnwindSafe for Subscriber
impl Send for Subscriber
impl Sync for Subscriber
impl Unpin for Subscriber
impl UnsafeUnpin for Subscriber
impl !UnwindSafe for Subscriber
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more