Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions taurus/README.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 6 additions & 6 deletions taurus/src/event/api_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down