Skip to main content

task_handler

Attribute Macro task_handler 

Source
#[task_handler]
Expand description

标记 TaskHandler 实现,编译期自动注册到 TASK_HANDLERS 分布式切片

配合 HandlerRegistry::from_discovered() 在运行时批量注册。

§参数

参数类型默认值说明
task_typei16必填任务类型标识,唯一
topic&str“task_{task_type}”Kafka topic
priorityNormal/High/Low/CriticalNormal优先级
timeout_secondsu64300超时秒数
max_retriesu323最大重试次数
description&str“”任务描述
dead_letter_topicOption<&str>None死信队列 topic

§示例

#[task_handler(task_type = 1, topic = "export", timeout_seconds = 60)]
struct ExportHandler;

#[async_trait]
impl TaskHandler for ExportHandler {
    fn task_type(&self) -> i16 { 1 }
    async fn execute(&self, payload: Value) -> Result<Value, String> {
        Ok(json!({"file": "https://..."}))
    }
}