引入WebSocketServer实现服务端秒杀消息推送

This commit is contained in:
小柒2012
2018-05-29 17:57:27 +08:00
parent cd74741d19
commit 1ec6a8a60a
8 changed files with 199 additions and 2 deletions

View File

@@ -1,8 +1,12 @@
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.webSocket.WebSocketServer;
import com.itstyle.seckill.service.ISeckillService;
/**
* 消费者
@@ -17,6 +21,13 @@ public class RedisConsumer {
public void receiveMessage(String message) {
//收到通道的消息之后执行秒杀操作(超卖)
String[] array = message.split(";");
seckillService.startSeckil(Long.parseLong(array[0]), Long.parseLong(array[1]));
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();
}
}
}
}