| | |
| | | package com.yeshi.fanli.util.mq.cmq;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.yeshi.utils.CMQUtil;
|
| | |
|
| | | 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;
|
| | |
|
| | | public class DouYinDeviceActiveCMQManager {
|
| | |
|
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25";
|
| | | private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo";
|
| | | private static DouYinDeviceActiveCMQManager jdOrderCMQManager;
|
| | | private static CMQUtil cmqUtil;
|
| | |
|
| | | public static String DOUYIN_DEVICE_ACTIVE = "douyin-device-active";
|
| | |
|
| | | static {
|
| | | cmqUtil = CMQUtil.getInstance(secretId, secretKey);
|
| | | DOUYIN_DEVICE_ACTIVE += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | cmqUtil.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);
|
| | | cmqUtil.sendMsg(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);
|
| | | cmqUtil.sendMsg(DOUYIN_DEVICE_ACTIVE, new Gson().toJson(dto));
|
| | | }
|
| | |
|
| | | public Map<String, DouYinDeviceActiveQueueDTO> consume(int count) {
|
| | | List<Message> list = cmqUtil.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) {
|
| | | cmqUtil.deleteMsg(DOUYIN_DEVICE_ACTIVE, receiptHandle);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.util.mq.cmq; |
| | | |
| | | import com.google.gson.Gson; |
| | | 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 javax.annotation.Resource; |
| | | |
| | | @Component |
| | | public class DouYinDeviceActiveCMQManager { |
| | | |
| | | @Resource |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | public static String DOUYIN_DEVICE_ACTIVE = "douyin-device-active"; |
| | | |
| | | static { |
| | | DOUYIN_DEVICE_ACTIVE += "-" + Constant.systemCommonConfig.getProjectName(); |
| | | |
| | | } |
| | | |
| | | |
| | | public void addDeviceActive(String device, int platform) { |
| | | if (StringUtil.isNullOrEmpty(device) || platform == 0) |
| | | return; |
| | | DouYinDeviceActiveQueueDTO dto = new DouYinDeviceActiveQueueDTO(DouYinDeviceActiveQueueDTO.TYPE_DEVICE, device, |
| | | platform); |
| | | 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); |
| | | RabbitmqSenderUtil.sendQueueMsg(rabbitTemplate, DOUYIN_DEVICE_ACTIVE, new Gson().toJson(dto)); |
| | | } |
| | | |
| | | } |