mirror of
https://gitee.com/52itstyle/spring-boot-seckill.git
synced 2026-03-18 07:50:21 +00:00
引入WebSocketServer实现服务端秒杀消息推送
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user