|
@@ -5,6 +5,7 @@ import com.ym.mec.biz.redisson.RedissonMessageService;
|
|
|
import com.ym.mec.biz.service.ImLiveBroadcastRoomService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RBucket;
|
|
|
+import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.ApplicationArguments;
|
|
@@ -43,24 +44,38 @@ public class RedissonTopicListener implements ApplicationRunner, Ordered {
|
|
|
log.error("RedissonMessageService subscribe sleep error", e);
|
|
|
}
|
|
|
|
|
|
- // 缓存JoinRoom用户信息到redis
|
|
|
- RBucket<Object> bucket = redissonClient.getBucket(RedissonMessageService.LIVE_ROOM_MEMBER + message);
|
|
|
- if (!bucket.isExists()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- bucket.delete();
|
|
|
-
|
|
|
- ImLiveBroadcastRoomVo imLiveBroadcastRoomVo = imLiveBroadcastRoomService.queryRoomInfo(message);
|
|
|
- if (Objects.isNull(imLiveBroadcastRoomVo)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ RLock lock = redissonClient.getLock(RedissonMessageService.LIVE_ROOM_MEMBER_LOCK + message);
|
|
|
try {
|
|
|
- imLiveBroadcastRoomService.setGroupMemberDefinedData(imLiveBroadcastRoomVo,imLiveBroadcastRoomVo.getLookNum(),imLiveBroadcastRoomVo.getTotalLookNum());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("RedissonMessageService subscribe setGroupMemberDefinedData error", e);
|
|
|
- bucket.set(message, 30, TimeUnit.MINUTES);
|
|
|
+ if (lock.tryLock()) {
|
|
|
+ // 缓存JoinRoom用户信息到redis
|
|
|
+ RBucket<Object> bucket = redissonClient.getBucket(RedissonMessageService.LIVE_ROOM_MEMBER + message);
|
|
|
+ if (!bucket.isExists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer times = (Integer) bucket.get();
|
|
|
+ bucket.delete();
|
|
|
+
|
|
|
+ ImLiveBroadcastRoomVo imLiveBroadcastRoomVo = imLiveBroadcastRoomService.queryRoomInfo(message);
|
|
|
+ if (Objects.isNull(imLiveBroadcastRoomVo)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ imLiveBroadcastRoomService.setGroupMemberDefinedData(imLiveBroadcastRoomVo,imLiveBroadcastRoomVo.getLookNum(),imLiveBroadcastRoomVo.getTotalLookNum());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("RedissonMessageService subscribe setGroupMemberDefinedData error", e);
|
|
|
+ if (times>=3) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ bucket.set(times +1, 30, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+ redissonMessageService.publish(RedissonMessageService.TOPIC_MESSAGE, message);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (lock.getHoldCount() != 0 && lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
}
|
|
|
- redissonMessageService.publish(RedissonMessageService.TOPIC_MESSAGE, message);
|
|
|
+
|
|
|
|
|
|
});
|
|
|
log.info("---> RedissonMessageService subscribe success");
|