1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.yanzuoguang.redis.mq;
import com.alibaba.fastjson.TypeReference;
import com.rabbitmq.client.Channel;
import com.yanzuoguang.mq.service.MqService;
import com.yanzuoguang.redis.PlanInfo;
import com.yanzuoguang.redis.service.PlanService;
import com.yanzuoguang.util.helper.JsonHelper;
import org.springframework.amqp.core.Message;
import org.springframework.stereotype.Component;
/**
* 任务消费
*
* @author 颜佐光
*/
@Component
public class PlanConsumer {
private final MqService mqService;
private final PlanService planService;
public PlanConsumer(MqService mqService, PlanService planService) {
this.mqService = mqService;
this.planService = planService;
}
/**
* 消费任务
*
* @param json 消息队列内容
* @param message 消息体
* @param channel 连接频道
*/
public void plan(String json, Message message, Channel channel) {
mqService.basicHandle(message,channel,json,content->{
PlanInfo<String> timeNew = JsonHelper.deserialize(json, new TypeReference<PlanInfo<String>>() {
});
// 获取运行的任务
planService.runPlan(timeNew);
});
}
}