UcEventBusIptv2ManagementUcEngine.java
5.17 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.topdraw.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.topdraw.business.module.task.template.constant.TaskEventName;
import com.topdraw.business.module.task.template.constant.TaskEventType;
import com.topdraw.exception.BadRequestException;
import com.topdraw.mq.domain.DataSyncMsg;
import com.topdraw.resttemplate.RestTemplateClient;
import com.topdraw.util.FileUtil;
import com.topdraw.util.JSONUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
@Component
@Slf4j
public class UcEventBusIptv2ManagementUcEngine {
@Autowired
private RestTemplateClient restTemplateClient;
/*@Value("#{rabbitMqErrorLogConfig.getEventBusError()}")
private Map<String, String> error;*/
/**
* 事件
* @param content
* @description 基础数据同步
* @author Hongyan Wang
* @date 2021/9/7 11:26 上午
*/
/*@RabbitHandler
@RabbitListener(queues = "#{rabbitMqSourceConfig.getEventBusQueue()}",
containerFactory = "#{rabbitMqSourceConfig.getEventBusSource()}",
autoStartup = "#{rabbitMqSourceConfig.getEventBusStartUp()}",
ackMode = "AUTO")*/
@RabbitHandler
@RabbitListener(queues = "#{rabbitMqConfig.getEventBusQueue()}",
ackMode = "AUTO")
public void eventBusConsumer(Channel channel, Message message, String content) throws Exception {
log.info(" receive dataSync msg , content is ==>> {} ", content);
try {
DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class);
log.info("解析后的参数 , playContent ==>> {} ", dataSyncMsg);
if (Objects.nonNull(dataSyncMsg)) {
String evt = dataSyncMsg.getEvt();
if (StringUtils.isBlank(evt)) {
log.error("eventBus事件类型(evt)为空");
throw new BadRequestException("参数错误,事件类型 evt不存在");
}
LocalDateTime time = dataSyncMsg.getTime();
if (Objects.isNull(time)) {
log.error("参数错误,事件发送时间(time)不存在");
throw new BadRequestException("参数错误,事件发送时间(time)不存在");
} /*else {
if (time.isAfter(LocalDateTime.now()) || time.toLocalDate().compareTo(LocalDate.now()) != 0) {
log.error("参数错误,事件发送时间(time)非法 ==>> {}", time);
throw new BadRequestException("参数错误,事件发送时间非法 ");
}
}*/
String msgData = dataSyncMsg.getMsgData();
if (StringUtils.isBlank(msgData)) {
log.error("eventBus事件消息体(msgData)为空");
throw new BadRequestException("参数错误,事件类型 evt不存在");
}
switch (dataSyncMsg.getEvt().toUpperCase()) {
// 播放记录
case TaskEventName.PLAY:
this.doPlayEvent(dataSyncMsg);
break;
default:
log.info("无可处理的任务");
break;
}
}
} catch (Exception e) {
log.error("eventBus 消费异常 ==>> {}",e.getMessage());
// TODO使用slf4j记录日志
/*if (MapUtils.isNotEmpty(error)) {
String errorStart = this.error.get("start");
if (errorStart.equalsIgnoreCase("true")) {
String fileName = this.error.get("fileName")+"_"+LocalDate.now() +".log";
String filePath = this.error.get("filePath");
String filePath1 = filePath+fileName;
FileUtil.writeStringToFile2(filePath1, content, e.getMessage());
}
}*/
}
log.info("eventBusConsumer ====>>>> end");
}
/**
*
* @param playContent
*/
private void doPlayEvent(DataSyncMsg playContent) {
playContent.setEvent(TaskEventType.PLAY);
String msgData = playContent.getMsgData();
JSONObject jsonObject = JSONObject.parseObject(msgData, JSONObject.class);
Object platformAccount = jsonObject.get("platformAccount");
if (Objects.nonNull(platformAccount)) {
JSONObject response = this.restTemplateClient.dealTask(playContent);
if (Objects.isNull(response)) {
log.error("uc-engine响应超时,请检查uc-engine服务");
throw new BadRequestException("uc-engine响应超时");
}
}
}
}