MessageCenterMqHandler.java
1.34 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
package com.yoho.message.sdk.common.handler;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.yoho.message.sdk.common.model.MessageCenterCommonEvent;
import com.yoho.message.sdk.common.mq.MessageProducerTemplate;
/**
* 消息中心事件处理器,上报到MQ
*
* @author hugufei
*
*/
@Component
public class MessageCenterMqHandler {
@Resource(name = "messageProducerTemplate")
private MessageProducerTemplate messageProducerTemplate;
@Value("${cloud:unknown}")
private String cloud;
private static final String MessageCenterTopic = "message-center-topic";
public void sendMessageToMq(MessageCenterCommonEvent event) {
String sendScene = event.getSendScene();
if (StringUtils.isBlank(sendScene)) {
return;
}
String sendSceneKey = event.getSendSceneKey();
if (StringUtils.isBlank(sendSceneKey)) {
return;
}
List<String> uids = event.getUidList();
if (uids == null || uids.isEmpty()) {
return;
}
JSONObject params = event.getParams();
if (params == null) {
params = new JSONObject();
event.setParams(params);
}
event.setSource(cloud);
messageProducerTemplate.send(MessageCenterTopic, event);
}
}