package cn.lili.listener; import cn.lili.cache.Cache; import cn.lili.modules.lmk.domain.entity.MyCollect; import cn.lili.modules.lmk.domain.entity.ThumbsUpRecord; import cn.lili.modules.lmk.domain.form.ThumbsUpRecordForm; import cn.lili.modules.lmk.service.ThumbsUpRecordService; import cn.lili.modules.lmk.service.VideoCommentService; import cn.lili.modules.lmk.service.VideoService; import cn.lili.rocketmq.tags.CommentTagsEnum; import cn.lili.rocketmq.tags.VideoTagsEnum; import com.alibaba.fastjson.JSON; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; import org.apache.rocketmq.spring.core.RocketMQListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * 评论消息消费者 * * @author paulG * @since 2020/12/9 **/ @Component @Slf4j @RocketMQMessageListener(topic = "${lili.data.rocketmq.video-topic}", consumerGroup = "${lili.data.rocketmq.video-group}") public class VideoMessageListener implements RocketMQListener { @Autowired private VideoService videoService; @Autowired private Cache cache; @Override public void onMessage(MessageExt messageExt) { try { String msg = new String(messageExt.getBody()); if (StringUtils.isBlank(msg)) { log.error("video msg is null, cant not consumer"); return; } switch (VideoTagsEnum.valueOf(messageExt.getTags())) { case COLLECT: this.collect(msg); break; default: log.error("video msg not match correct tag, consumer err"); break; } } catch (Exception e) { log.error("video msg consumer err", e); } } /** * 视频收藏/取消收藏 * * @param msg */ public void collect(String msg) { MyCollect collect = JSON.parseObject(msg, MyCollect.class); videoService.mqCollectChange(collect); } }