| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.yeshi.fanli.util.mq.cmq.TDMQUtil; |
| | | import org.yeshi.utils.CMQUtil; |
| | | |
| | | import com.qcloud.cmq.Message; |
| | |
| | | |
| | | public class VipShopOrderCMQManager { |
| | | |
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25"; |
| | | private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo"; |
| | | private static VipShopOrderCMQManager vipShopOrderCMQManager; |
| | | private static CMQUtil cmqUtil; |
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25"; |
| | | private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo"; |
| | | private static VipShopOrderCMQManager vipShopOrderCMQManager; |
| | | private static CMQUtil cmqUtil; |
| | | |
| | | public static String VIPSHOP_ORDER = "order-vipshop"; |
| | | public static String VIPSHOP_ORDER = "order-vipshop"; |
| | | |
| | | static { |
| | | cmqUtil = CMQUtil.getInstance(secretId, secretKey); |
| | | VIPSHOP_ORDER += "-" + Constant.systemCommonConfig.getProjectName(); |
| | | cmqUtil.createQueue(VIPSHOP_ORDER); |
| | | } |
| | | static { |
| | | cmqUtil = CMQUtil.getInstance(secretId, secretKey); |
| | | VIPSHOP_ORDER += "-" + Constant.systemCommonConfig.getProjectName(); |
| | | TDMQUtil.getInstance().init(secretId, secretKey, Constant.TDMQ_PUBLIC); |
| | | TDMQUtil.getInstance().createQueue(VIPSHOP_ORDER); |
| | | } |
| | | |
| | | public static VipShopOrderCMQManager getInstance() { |
| | | if (vipShopOrderCMQManager == null) |
| | | vipShopOrderCMQManager = new VipShopOrderCMQManager(); |
| | | return vipShopOrderCMQManager; |
| | | } |
| | | public static VipShopOrderCMQManager getInstance() { |
| | | if (vipShopOrderCMQManager == null) |
| | | vipShopOrderCMQManager = new VipShopOrderCMQManager(); |
| | | return vipShopOrderCMQManager; |
| | | } |
| | | |
| | | /** |
| | | * 添加唯品会订单到队列 |
| | | * |
| | | * @param orderId |
| | | */ |
| | | public void addVipShopOrder(String orderId) { |
| | | if (StringUtil.isNullOrEmpty(orderId)) |
| | | return; |
| | | cmqUtil.sendMsg(VIPSHOP_ORDER, orderId); |
| | | } |
| | | /** |
| | | * 添加唯品会订单到队列 |
| | | * |
| | | * @param orderId |
| | | */ |
| | | public void addVipShopOrder(String orderId) { |
| | | if (StringUtil.isNullOrEmpty(orderId)) |
| | | return; |
| | | TDMQUtil.getInstance().sendMsg(VIPSHOP_ORDER, orderId); |
| | | } |
| | | |
| | | /** |
| | | * 消费队列消息 |
| | | * |
| | | * @param count |
| | | * @return |
| | | */ |
| | | public Map<String, String> consumeVipShopOrder(int count) { |
| | | List<Message> list = cmqUtil.recieveMsg(count, VIPSHOP_ORDER); |
| | | Map<String, String> map = new HashMap<>(); |
| | | if (list != null) |
| | | for (Message msg : list) { |
| | | String result = msg.msgBody; |
| | | map.put(msg.receiptHandle, result); |
| | | } |
| | | return map; |
| | | } |
| | | /** |
| | | * 消费队列消息 |
| | | * |
| | | * @param count |
| | | * @return |
| | | */ |
| | | public Map<String, String> consumeVipShopOrder(int count) { |
| | | List<Message> list = Constant.TDMQ_CONSUMER ? TDMQUtil.getInstance().recieveMsg(count, VIPSHOP_ORDER) : cmqUtil.recieveMsg(count, VIPSHOP_ORDER); |
| | | Map<String, String> map = new HashMap<>(); |
| | | if (list != null) |
| | | for (Message msg : list) { |
| | | String result = msg.msgBody; |
| | | map.put(msg.receiptHandle, result); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 删除唯品会队列 |
| | | * |
| | | * @param receiptHandle |
| | | */ |
| | | public void deleteVipShopOrder(String receiptHandle) { |
| | | cmqUtil.deleteMsg(VIPSHOP_ORDER, receiptHandle); |
| | | } |
| | | /** |
| | | * 删除唯品会队列 |
| | | * |
| | | * @param receiptHandle |
| | | */ |
| | | public void deleteVipShopOrder(String receiptHandle) { |
| | | if (Constant.TDMQ_CONSUMER) { |
| | | TDMQUtil.getInstance().deleteMsg(VIPSHOP_ORDER, receiptHandle); |
| | | } else { |
| | | cmqUtil.deleteMsg(VIPSHOP_ORDER, receiptHandle); |
| | | } |
| | | } |
| | | |
| | | } |