From 50b07b1fcb9dd3b6ae04ac16cb637088ad2d050b Mon Sep 17 00:00:00 2001 From: Neon Date: Sat, 10 Aug 2024 13:51:44 +0800 Subject: [PATCH 1/2] doc: taurus readme --- taurus/README.md | 19 +++++++++++++++++++ taurus/src/event/api_request.rs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) 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..6c0bdd2fe 100644 --- a/taurus/src/event/api_request.rs +++ b/taurus/src/event/api_request.rs @@ -5,7 +5,7 @@ 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. \ From dac27798c4d59d29173162d6db3be01b74ed7980 Mon Sep 17 00:00:00 2001 From: Neon Date: Sat, 10 Aug 2024 20:39:30 +0800 Subject: [PATCH 2/2] doc: update comment --- taurus/src/event/api_request.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/taurus/src/event/api_request.rs b/taurus/src/event/api_request.rs index 6c0bdd2fe..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,