| | |
| | | package com.yeshi.fanli.util.mq.cmq; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.qcloud.cmq.Message; |
| | | import com.yeshi.fanli.dto.ad.DouYinDeviceActiveQueueDTO; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.mq.rabbit.RabbitmqSenderUtil; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.annotation.Resource; |
| | | |
| | | @Component |
| | | public class DouYinDeviceActiveCMQManager { |
| | | |
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25"; |
| | | private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo"; |
| | | private static DouYinDeviceActiveCMQManager jdOrderCMQManager; |
| | | @Resource |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | public static String DOUYIN_DEVICE_ACTIVE = "douyin-device-active"; |
| | | |
| | | static { |
| | | TDMQUtil.getInstance().init(secretId, secretKey, Constant.TDMQ_PUBLIC); |
| | | |
| | | DOUYIN_DEVICE_ACTIVE += "-" + Constant.systemCommonConfig.getProjectName(); |
| | | TDMQUtil.getInstance().createQueue(DOUYIN_DEVICE_ACTIVE); |
| | | |
| | | } |
| | | |
| | | public static DouYinDeviceActiveCMQManager getInstance() { |
| | | if (jdOrderCMQManager == null) |
| | | jdOrderCMQManager = new DouYinDeviceActiveCMQManager(); |
| | | return jdOrderCMQManager; |
| | | } |
| | | |
| | | public void addDeviceActive(String device, int platform) { |
| | | if (StringUtil.isNullOrEmpty(device) || platform == 0) |
| | | return; |
| | | DouYinDeviceActiveQueueDTO dto = new DouYinDeviceActiveQueueDTO(DouYinDeviceActiveQueueDTO.TYPE_DEVICE, device, |
| | | platform); |
| | | TDMQUtil.getInstance().sendMsg(DOUYIN_DEVICE_ACTIVE, new Gson().toJson(dto)); |
| | | RabbitmqSenderUtil.sendQueueMsg(rabbitTemplate, DOUYIN_DEVICE_ACTIVE, new Gson().toJson(dto)); |
| | | } |
| | | |
| | | public void addAdActive(String callback) { |
| | | if (StringUtil.isNullOrEmpty(callback)) |
| | | return; |
| | | DouYinDeviceActiveQueueDTO dto = new DouYinDeviceActiveQueueDTO(DouYinDeviceActiveQueueDTO.TYPE_AD, callback); |
| | | TDMQUtil.getInstance().sendMsg(DOUYIN_DEVICE_ACTIVE, new Gson().toJson(dto)); |
| | | } |
| | | |
| | | public Map<String, DouYinDeviceActiveQueueDTO> consume(int count) { |
| | | List<Message> list = TDMQUtil.getInstance().recieveMsg(count, DOUYIN_DEVICE_ACTIVE); |
| | | Map<String, DouYinDeviceActiveQueueDTO> map = new HashMap<>(); |
| | | if (list != null) |
| | | for (Message msg : list) { |
| | | String result = msg.msgBody; |
| | | map.put(msg.receiptHandle, new Gson().fromJson(result, DouYinDeviceActiveQueueDTO.class)); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | public void delete(String receiptHandle) { |
| | | TDMQUtil.getInstance().deleteMsg(DOUYIN_DEVICE_ACTIVE, receiptHandle); |
| | | RabbitmqSenderUtil.sendQueueMsg(rabbitTemplate, DOUYIN_DEVICE_ACTIVE, new Gson().toJson(dto)); |
| | | } |
| | | |
| | | } |