接入层
责任链模式
什么是责任链模式?
初始化
sequenceDiagram
participant PC as PipelineConfig
participant PC2 as ProcessController
participant TPC as TaskPipelineConfig
note over PC: 初始化执行步骤
PC->>PC: commonSendTemplate
PC->>PC: recallMessageTemplate
PC->>PC: apiProcessController
note over TPC: 初始化执行步骤
TPC->>TPC: taskTemplate
TPC->>TPC: processController
note over PC2: 填充流程模板
PC->>PC2: put
TPC->>PC2: put
执行
- 发送消息:
SendServiceImpl.send
->ProcessController.process
- 撤回消息:
RecallServiceImpl.recall
->ProcessController.process
- 消费消息:
Task.run
->ProcessController.process
流程模板
graph LR
A[ProcessModel]
A-->A1[SendTaskModel 发送任务模型]
A-->A2[RecallTaskModel 撤回任务模型]
A-->A3[TaskInfo 任务信息]
B[BusinessProcess<T extends ProcessModel>]
B-->B1[BusinessProcess<SendTaskModel> 发送消息]
B-->B2[BusinessProcess<RecallTaskModel> 撤回消息]
B-->B3[BusinessProcess<TaskInfo> 消费消息]
B1-->B11[SendPreCheckAction 前置处理]
B1-->B12[SendAssembleAction 参数拼装]
B1-->B13[SendAfterCheckAction 后置处理]
B1-->B14[SendMqAction 消息发送]
B2-->B21[RecallAssembleAction]
B2-->B22[RecallMqAction]
B3-->B31[DiscardAction 消息丢弃]
B3-->B32[ShieldAction 消息屏蔽]
B3-->B33[DeduplicationAction 消息去重]
B3-->B34[SensWordsAction 敏感词过滤]
B3-->B35[SendMessageAction 消息发送]
前置检查
校验必填字段:过滤消息模板 ID 或 MessageParam
为空的情况。
过滤空接收者:过滤 MessageParam
中 receiver
为空的情况。
限制批量大小:过滤 MessageParam
中 receiver > 100
的情况。
- 后续的定时任务批量发送,虽然 CSV 文件中的 receiver 可以大于 100,但是在具体处理逻辑中,还是将 CSV 文件拆分为多个批次发送,每次不超过 100。
参数拼装
目的:组装 TaskInfo
中的 ContentModel
属性。
调用流程:process
-> assembleTaskInfo
-> getContentModelValue
-> ContentHolderUtil
-> PropertyPlaceholddanerHelper
(Spring 中的工具类)
细节:通过工具类替换占位符后,将替换后的字符串通过反射映射到 ContentModel
中。
后置检查
确定校验规则:根据模板配置的 idType
(手机号||邮箱)选取对应正则表达式。
过滤非法请求:根据正则表达式过滤非法的 receiver
。如果某个批量发送任务的 receiver
被删空,则移除该 TaskInfo
。