diff --git a/taurus/README.md b/taurus/README.md index 1af45fb61..2e060d070 100644 --- a/taurus/README.md +++ b/taurus/README.md @@ -1,2 +1,21 @@ # Message Queue Module + +## Intro This module offers mega the ability to send and handle specific events. + +After sending the event you created into a global message queue, it will be received in a handler thread and run the callback function defined in trait `EventBase`. + +The events would also be asynchronously flush into database for further investigation. + +## New Customized Event + +If you want to make a new event type and use it in other modules, you should do as follows. + +- Create a event struct which implements trait `EventBase`. +- Give your new event a way to enqueue itself into the message queue. +- Add a enum variation in `EventType` which is defined in `src/event/mod.rs`. +- Fill the missing match arms in `src/event/mod.rs` and `src/queue.rs`. +- Import and use it. + +> Tips: +> Check `src/event/api_request.rs` for a brief example. diff --git a/taurus/src/event/api_request.rs b/taurus/src/event/api_request.rs index d2323348d..b2cd77227 100644 --- a/taurus/src/event/api_request.rs +++ b/taurus/src/event/api_request.rs @@ -5,13 +5,13 @@ use async_trait::async_trait; use crate::{event::EventBase, event::EventType, queue::get_mq}; /// # Api Request Event -/// --- -/// This is a example event definition for using message queue. \ /// -/// Your customized event should implement `EventBase` trait. \ -/// Then the event can be wrapped and put into message queue. \ -/// The message `id` and `create_time` will be attached to your event -/// and then wrapped as a `Message`. \ +/// This is a example event definition for using message queue. +/// +/// Your customized event should implement `EventBase` trait. +/// Then the event can be wrapped and put into message queue. +/// The message `id` and `create_time` will be attached to your +/// event and then wrapped as a `Message`. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ApiRequestEvent { pub api: ApiType,