MessageCenterMqHandler.java 1.34 KB
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);
	}

}