mirror of
https://github.com/qiurunze123/miaosha.git
synced 2023-11-19 22:41:03 +08:00
提交消息模式
This commit is contained in:
parent
97247a23d5
commit
1c97767d55
|
@ -1,12 +1,15 @@
|
|||
package com.geekq.miaosha.controller;
|
||||
|
||||
import com.geekq.miaosha.common.SnowflakeIdWorker;
|
||||
import com.geekq.miaosha.domain.MiaoShaMessageUser;
|
||||
import com.geekq.miaosha.rabbitmq.MQSender;
|
||||
import com.geekq.miaosha.service.MiaoShaMessageService;
|
||||
import com.geekq.miaosha.vo.MiaoShaMessageVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
|
@ -19,10 +22,15 @@ public class MiaoShaMessageController {
|
|||
private MQSender sendMessage;
|
||||
|
||||
@RequestMapping(value="/list", produces="text/html")
|
||||
public String list() {
|
||||
public void list() {
|
||||
|
||||
// List<MiaoShaMessageUser> messageUserList = messageService.getMessage("");
|
||||
MiaoShaMessageVo vo = new MiaoShaMessageVo();
|
||||
vo.setContent("尊敬的用户你好,你已经成功注册!");
|
||||
vo.setCreateTime(new Date());
|
||||
vo.setMessageId(SnowflakeIdWorker.getOrderId(0,0));
|
||||
vo.setSendType(0);
|
||||
vo.setStatus(0);
|
||||
vo.setUserId(Long.valueOf(22));
|
||||
sendMessage.sendMessage(null);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public class MiaoShaMessage implements Serializable {
|
|||
|
||||
private Integer id ;
|
||||
|
||||
private String messageId ;
|
||||
private Long messageId ;
|
||||
|
||||
private String content ;
|
||||
|
||||
|
@ -38,11 +38,11 @@ public class MiaoShaMessage implements Serializable {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMessageId() {
|
||||
public Long getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(String messageId) {
|
||||
public void setMessageId(Long messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,60 +1,30 @@
|
|||
package com.geekq.miaosha.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 消息中心用戶存储关系表
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MiaoShaMessageUser implements Serializable {
|
||||
|
||||
private Integer id ;
|
||||
private Long id ;
|
||||
|
||||
private Integer userId ;
|
||||
private Long userId ;
|
||||
|
||||
private String messageId ;
|
||||
private Long messageId ;
|
||||
|
||||
private String goodId ;
|
||||
|
||||
private Date orderId;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(String messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public String getGoodId() {
|
||||
return goodId;
|
||||
}
|
||||
|
||||
public void setGoodId(String goodId) {
|
||||
this.goodId = goodId;
|
||||
}
|
||||
|
||||
public Date getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(Date orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class MQConfig {
|
|||
|
||||
public static final String EXCHANGE_TOPIC = "exchange_topic";
|
||||
|
||||
public static final String MIAOSHA_MESSAGE = "miaosha_message";
|
||||
public static final String MIAOSHA_MESSAGE = "miaosha_mess";
|
||||
|
||||
public static final String QUEUE = "queue";
|
||||
public static final String TOPIC_QUEUE1 = "topic.queue1";
|
||||
|
|
|
@ -4,16 +4,22 @@ import com.geekq.miaosha.domain.MiaoshaOrder;
|
|||
import com.geekq.miaosha.domain.MiaoshaUser;
|
||||
import com.geekq.miaosha.redis.RedisService;
|
||||
import com.geekq.miaosha.service.GoodsService;
|
||||
import com.geekq.miaosha.service.MiaoShaMessageService;
|
||||
import com.geekq.miaosha.service.MiaoshaService;
|
||||
import com.geekq.miaosha.service.OrderService;
|
||||
import com.geekq.miaosha.vo.GoodsVo;
|
||||
import com.geekq.miaosha.vo.MiaoShaMessageVo;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
public class MQReceiver {
|
||||
|
||||
|
@ -31,6 +37,9 @@ public class MQReceiver {
|
|||
@Autowired
|
||||
MiaoshaService miaoshaService;
|
||||
|
||||
@Autowired
|
||||
MiaoShaMessageService messageService ;
|
||||
|
||||
@RabbitListener(queues=MQConfig.MIAOSHA_QUEUE)
|
||||
public void receive(String message) {
|
||||
log.info("receive message:"+message);
|
||||
|
@ -55,9 +64,10 @@ public class MQReceiver {
|
|||
|
||||
|
||||
@RabbitListener(queues=MQConfig.MIAOSHA_MESSAGE)
|
||||
@RabbitHandler
|
||||
public void receiveMiaoShaMessage(Object message) {
|
||||
System.out.println(111111);
|
||||
System.out.println(message);
|
||||
public void receiveMiaoShaMessage(Message message, Channel channel) throws IOException {
|
||||
log.info("接受到的消息为:{}",message);
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
|
||||
// MiaoShaMessageVo msm = RedisService.stringToBean((String) message, MiaoShaMessageVo.class);
|
||||
// messageService.insertMs(msm);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.geekq.miaosha.rabbitmq;
|
||||
|
||||
import com.geekq.miaosha.domain.MiaoshaUser;
|
||||
import com.geekq.miaosha.redis.RedisService;
|
||||
import com.geekq.miaosha.vo.MiaoShaMessageVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
|
@ -35,5 +37,13 @@ public class MQSender {
|
|||
rabbitTemplate.convertAndSend(MQConfig.EXCHANGE_TOPIC,"miaosha_*", "111111111");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 站内信
|
||||
* @param
|
||||
*/
|
||||
public void sendRegisterMessage(MiaoShaMessageVo miaoShaMessageVo) {
|
||||
String msg = RedisService.beanToString(miaoShaMessageVo);
|
||||
log.info("send message:{}" , msg);
|
||||
rabbitTemplate.convertAndSend(MQConfig.EXCHANGE_TOPIC,"miaosha_*", msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.geekq.miaosha.service;
|
|||
|
||||
import com.geekq.miaosha.dao.MiaoShaMessageDao;
|
||||
import com.geekq.miaosha.domain.MiaoShaMessageUser;
|
||||
import com.geekq.miaosha.vo.MiaoShaMessageVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -19,4 +20,12 @@ public class MiaoShaMessageService {
|
|||
|
||||
return messageUserList;
|
||||
}
|
||||
|
||||
|
||||
public void insertMs(MiaoShaMessageVo miaoShaMessageVo){
|
||||
MiaoShaMessageUser mu = new MiaoShaMessageUser() ;
|
||||
mu.setUserId(miaoShaMessageVo.getUserId());
|
||||
mu.setMessageId(miaoShaMessageVo.getMessageId());
|
||||
messageDao.insertMiaoShaMessageUser(mu);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
package com.geekq.miaosha.service;
|
||||
|
||||
import com.geekq.miaosha.common.SnowflakeIdWorker;
|
||||
import com.geekq.miaosha.controller.RegisterController;
|
||||
import com.geekq.miaosha.dao.MiaoShaUserDao;
|
||||
import com.geekq.miaosha.domain.MiaoshaUser;
|
||||
import com.geekq.miaosha.exception.GlobleException;
|
||||
import com.geekq.miaosha.rabbitmq.MQSender;
|
||||
import com.geekq.miaosha.redis.MiaoShaUserKey;
|
||||
import com.geekq.miaosha.redis.RedisService;
|
||||
import com.geekq.miaosha.utils.MD5Utils;
|
||||
import com.geekq.miaosha.utils.UUIDUtil;
|
||||
import com.geekq.miaosha.vo.LoginVo;
|
||||
import com.geekq.miaosha.vo.MiaoShaMessageVo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -34,6 +37,9 @@ public class MiaoShaUserService {
|
|||
@Autowired
|
||||
private RedisService redisService ;
|
||||
|
||||
@Autowired
|
||||
private MQSender sender ;
|
||||
|
||||
|
||||
public MiaoshaUser getByToken(HttpServletResponse response , String token) {
|
||||
|
||||
|
@ -97,6 +103,17 @@ public class MiaoShaUserService {
|
|||
if(user == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
MiaoShaMessageVo vo = new MiaoShaMessageVo();
|
||||
vo.setContent("尊敬的用户你好,你已经成功注册!");
|
||||
vo.setCreateTime(new Date());
|
||||
vo.setMessageId(SnowflakeIdWorker.getOrderId(0,0));
|
||||
vo.setSendType(0);
|
||||
vo.setStatus(0);
|
||||
vo.setUserId(miaoShaUser.getId());
|
||||
sender.sendRegisterMessage(vo);
|
||||
|
||||
|
||||
//生成cookie 将session返回游览器 分布式session
|
||||
String token= UUIDUtil.uuid();
|
||||
addCookie(response, token, user);
|
||||
|
@ -106,6 +123,7 @@ public class MiaoShaUserService {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean login(HttpServletResponse response , LoginVo loginVo) {
|
||||
if(loginVo ==null){
|
||||
throw new GlobleException(SYSTEM_ERROR);
|
||||
|
|
43
src/main/java/com/geekq/miaosha/vo/MiaoShaMessageVo.java
Normal file
43
src/main/java/com/geekq/miaosha/vo/MiaoShaMessageVo.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package com.geekq.miaosha.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
@Setter
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MiaoShaMessageVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1341750239648941486L;
|
||||
private Integer id ;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String goodId ;
|
||||
|
||||
private Date orderId;
|
||||
|
||||
private Long messageId ;
|
||||
|
||||
private String content ;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Integer status ;
|
||||
|
||||
private Date overTime ;
|
||||
|
||||
private Integer messageType ;
|
||||
|
||||
private Integer sendType ;
|
||||
|
||||
private String goodName ;
|
||||
|
||||
private BigDecimal price ;
|
||||
}
|
Loading…
Reference in New Issue
Block a user