| | |
| | | package com.yeshi.makemoney.app.utils.mq; |
| | | |
| | | import com.alipay.api.response.AlipayFundTransUniTransferResponse; |
| | | import com.google.gson.Gson; |
| | | import com.qcloud.cmq.Message; |
| | | import com.yeshi.makemoney.app.dto.mq.AddGoldCornMQMsg; |
| | | import com.yeshi.makemoney.app.dto.mq.ExtractTransferResultMQMsg; |
| | | import com.yeshi.makemoney.app.entity.money.Extract; |
| | | import org.yeshi.utils.CMQUtil; |
| | | import com.yeshi.makemoney.app.dto.mq.GoldCornSettleMQMsg; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.mq.TDMQUtil; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | * @date 2022/4/1 17:06 |
| | | */ |
| | | public class CMQManager { |
| | | Logger logger= LoggerFactory.getLogger(CMQManager.class); |
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25"; |
| | | private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo"; |
| | | private static CMQManager cmqManager; |
| | | private static TDMQUtil tdmqUtil; |
| | | |
| | | public static String EXTRACT_RESULT = "makemoney-extract-result"; |
| | | public static String QUEUE_EXTRACT_RESULT = "makemoney-extract-result"; |
| | | |
| | | public static String QUEUE_ADD_GOLDCORN = "makemoney-add-goldcorn"; |
| | | |
| | | public static String QUEUE_GOLDCORN_SETTLE = "makemoney-goldcorn-settle"; |
| | | |
| | | static { |
| | | TDMQUtil.getInstance().init(secretId, secretKey, true); |
| | | tdmqUtil = TDMQUtil.getInstance(); |
| | | tdmqUtil.createQueue(EXTRACT_RESULT); |
| | | tdmqUtil.createQueue(QUEUE_EXTRACT_RESULT); |
| | | tdmqUtil.createQueue(QUEUE_ADD_GOLDCORN); |
| | | tdmqUtil.createQueue(QUEUE_GOLDCORN_SETTLE); |
| | | } |
| | | |
| | | public static CMQManager getInstance() { |
| | |
| | | */ |
| | | public void addExtractResultMsg(ExtractTransferResultMQMsg msg) { |
| | | String content = new Gson().toJson(msg); |
| | | tdmqUtil.sendMsg(EXTRACT_RESULT, content); |
| | | tdmqUtil.sendMsg(QUEUE_EXTRACT_RESULT, content); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public Map<String, ExtractTransferResultMQMsg> consumeExtractResultMsg(int count) { |
| | | List<Message> list = tdmqUtil.recieveMsg(count, EXTRACT_RESULT); |
| | | List<Message> list = tdmqUtil.recieveMsg(count, QUEUE_EXTRACT_RESULT); |
| | | Map<String, ExtractTransferResultMQMsg> map = new HashMap<>(); |
| | | if (list != null) { |
| | | for (Message msg : list) { |
| | |
| | | * @param receiptHandle |
| | | */ |
| | | public void deleteExtractResultMsg(String receiptHandle) { |
| | | tdmqUtil.deleteMsg(EXTRACT_RESULT, receiptHandle); |
| | | tdmqUtil.deleteMsg(QUEUE_EXTRACT_RESULT, receiptHandle); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加金币 |
| | | **/ |
| | | |
| | | public void addAddGoldCornMsg(AddGoldCornMQMsg msg) { |
| | | String content = new Gson().toJson(msg); |
| | | |
| | | tdmqUtil.sendMsg(QUEUE_ADD_GOLDCORN, content); |
| | | } |
| | | |
| | | public Map<String, AddGoldCornMQMsg> consumeAddGoldCornMsg(int count) { |
| | | List<Message> list = tdmqUtil.recieveMsg(count, QUEUE_ADD_GOLDCORN); |
| | | Map<String, AddGoldCornMQMsg> map = new HashMap<>(); |
| | | if (list != null) { |
| | | for (Message msg : list) { |
| | | String result = msg.msgBody; |
| | | if (!StringUtil.isNullOrEmpty(result)) { |
| | | AddGoldCornMQMsg resultMQMsg = new Gson().fromJson(result, |
| | | AddGoldCornMQMsg.class); |
| | | map.put(msg.receiptHandle, resultMQMsg); |
| | | } |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | public void deleteAddGoldCornMsg(String receiptHandle) { |
| | | tdmqUtil.deleteMsg(QUEUE_ADD_GOLDCORN, receiptHandle); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 金币结算 |
| | | **/ |
| | | public void addGoldCornSettleMsg(GoldCornSettleMQMsg msg) { |
| | | String content = new Gson().toJson(msg); |
| | | logger.debug("添加结算消息开始:",content); |
| | | TDMQUtil.getInstance().sendMsg(QUEUE_GOLDCORN_SETTLE, content); |
| | | //添加日志 |
| | | logger.debug("添加结算消息结束:{}",content); |
| | | } |
| | | /** |
| | | * 批量添加 |
| | | **/ |
| | | public void addGoldCornSettleMsg(List<GoldCornSettleMQMsg> msgList) throws Exception { |
| | | List<String> contentList=new ArrayList<>(); |
| | | for(GoldCornSettleMQMsg msg:msgList) { |
| | | contentList.add(new Gson().toJson(msg)); |
| | | } |
| | | logger.debug("添加结算消息开始:{}",msgList.size()); |
| | | TDMQUtil.getInstance().batchSendMsg(QUEUE_GOLDCORN_SETTLE, contentList); |
| | | //添加日志 |
| | | logger.debug("添加结算消息结束:{}",msgList.size()); |
| | | } |
| | | |
| | | public Map<String, GoldCornSettleMQMsg> consumeGoldCornSettleMsg(int count) { |
| | | List<Message> list = TDMQUtil.getInstance().recieveMsg(count, QUEUE_GOLDCORN_SETTLE); |
| | | Map<String, GoldCornSettleMQMsg> map = new HashMap<>(); |
| | | if (list != null) { |
| | | for (Message msg : list) { |
| | | String result = msg.msgBody; |
| | | if (!StringUtil.isNullOrEmpty(result)) { |
| | | GoldCornSettleMQMsg resultMQMsg = new Gson().fromJson(result, |
| | | GoldCornSettleMQMsg.class); |
| | | map.put(msg.receiptHandle, resultMQMsg); |
| | | } |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | public void deleteGoldCornSettleMsg(String receiptHandle) { |
| | | TDMQUtil.getInstance().deleteMsg(QUEUE_GOLDCORN_SETTLE, receiptHandle); |
| | | } |
| | | |
| | | |