mirror of
https://gitee.com/52itstyle/spring-boot-seckill.git
synced 2026-03-07 10:30:18 +00:00
队列秒杀WebSocket异步通知用户秒杀结果
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package com.itstyle.seckill.queue.redis;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.itstyle.seckill.common.entity.Result;
|
||||
import com.itstyle.seckill.common.redis.RedisUtil;
|
||||
import com.itstyle.seckill.common.webSocket.WebSocketServer;
|
||||
import com.itstyle.seckill.service.ISeckillService;
|
||||
/**
|
||||
@@ -18,16 +17,21 @@ public class RedisConsumer {
|
||||
@Autowired
|
||||
private ISeckillService seckillService;
|
||||
|
||||
private static RedisUtil redisUtil = new RedisUtil();
|
||||
|
||||
public void receiveMessage(String message) {
|
||||
//收到通道的消息之后执行秒杀操作(超卖)
|
||||
String[] array = message.split(";");
|
||||
Result result = seckillService.startSeckilAopLock(Long.parseLong(array[0]), Long.parseLong(array[1]));
|
||||
if(result.equals(Result.ok())){
|
||||
try {
|
||||
WebSocketServer.sendInfo(array[0].toString(), array[1].toString());//推送给前台
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(redisUtil.getValue(array[0])!=null){//control层已经判断了,其实这里不需要再判断了
|
||||
Result result = seckillService.startSeckilAopLock(Long.parseLong(array[0]), Long.parseLong(array[1]));
|
||||
if(result.equals(Result.ok())){
|
||||
WebSocketServer.sendInfo(array[0].toString(), "秒杀成功");//推送给前台
|
||||
}else{
|
||||
WebSocketServer.sendInfo(array[0].toString(), "秒杀失败");//推送给前台
|
||||
redisUtil.cacheValue(array[0], "ok");//秒杀结束
|
||||
}
|
||||
}else{
|
||||
WebSocketServer.sendInfo(array[0].toString(), "秒杀失败");//推送给前台
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user