集成rocketMq消息队列收发消息

This commit is contained in:
海言
2025-10-13 15:21:33 +08:00
parent 800dc8f878
commit 56fdc15090
8 changed files with 117 additions and 6 deletions

View File

@@ -12,16 +12,19 @@ import cn.xf.basedemo.config.GlobalConfig;
import cn.xf.basedemo.mappers.UserMapper;
import cn.xf.basedemo.model.domain.User;
import cn.xf.basedemo.model.res.LoginInfoRes;
import cn.xf.basedemo.mq.RocketMqMsgProducer;
import cn.xf.basedemo.service.UserService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@@ -49,6 +52,9 @@ public class UserServiceImpl implements UserService {
@Autowired
private RedisTemplate redisTemplate;
@Resource
private RocketMqMsgProducer rocketMqMsgProducer;
@Override
public RetObj login(LoginInfoRes res) {
@@ -116,4 +122,10 @@ public class UserServiceImpl implements UserService {
}
return RetObj.error("es中不存在该用户");
}
@Override
public RetObj sendMQMsg(String msg) {
rocketMqMsgProducer.sendMsg("user-topic", msg);
return RetObj.success();
}
}