im客服错误日志打印
This commit is contained in:
parent
9cbf01f2ab
commit
33f83bc82d
@ -2,6 +2,7 @@ package com.suisung.mall.im.common.websocket.service;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -13,6 +14,8 @@ import java.util.stream.Collectors;
|
|||||||
public class DistributedSessionService {
|
public class DistributedSessionService {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(DistributedSessionService.class);
|
private static final Logger log = LoggerFactory.getLogger(DistributedSessionService.class);
|
||||||
|
|
||||||
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
@ -169,16 +172,17 @@ public class DistributedSessionService {
|
|||||||
// 获取所有服务器的用户集合
|
// 获取所有服务器的用户集合
|
||||||
Set<String> serverKeys = redisTemplate.keys(SERVER_USERS_KEY + "*");
|
Set<String> serverKeys = redisTemplate.keys(SERVER_USERS_KEY + "*");
|
||||||
List<Integer> allUserIds = new ArrayList<>();
|
List<Integer> allUserIds = new ArrayList<>();
|
||||||
|
log.info("sserverKeys-{}", serverKeys);
|
||||||
if (serverKeys != null) {
|
if (serverKeys != null) {
|
||||||
for (String serverKey : serverKeys) {
|
for (String serverKey : serverKeys) {
|
||||||
Set<Object> userIds = redisTemplate.opsForSet().members(serverKey);
|
Set<Object> userIds = redisTemplate.opsForSet().members(serverKey);
|
||||||
|
log.info("userIds{}", userIds);
|
||||||
if (userIds != null) {
|
if (userIds != null) {
|
||||||
userIds.forEach(userIdStr -> {
|
userIds.forEach(userIdStr -> {
|
||||||
try {
|
try {
|
||||||
allUserIds.add(Integer.parseInt(userIdStr.toString()));
|
allUserIds.add(Integer.parseInt(userIdStr.toString()));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// 忽略格式错误的用户ID
|
log.info("报错:{}",e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -299,10 +299,14 @@ public class MallsuiteImSocketHandler implements WebSocketHandler {
|
|||||||
* 广播在线状态到本地用户
|
* 广播在线状态到本地用户
|
||||||
*/
|
*/
|
||||||
private void broadcastLocalOnlineStatus(SendVO message) {
|
private void broadcastLocalOnlineStatus(SendVO message) {
|
||||||
if (localSessionManager == null) {
|
logger.info("localSessionManager: {}", localSessionManager);
|
||||||
|
logger.info("localSessionManager.userSessions: {}", localSessionManager.userSessions);
|
||||||
|
logger.info("localSessionManager.userSessions.values: {}", localSessionManager.userSessions.values());
|
||||||
|
if (localSessionManager == null || localSessionManager.userSessions.isEmpty()) {
|
||||||
logger.error("localSessionManager is null, cannot broadcast online status");
|
logger.error("localSessionManager is null, cannot broadcast online status");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取本地所有用户会话
|
// 获取本地所有用户会话
|
||||||
for (List<WebSocketSession> sessions : localSessionManager.userSessions.values()) {
|
for (List<WebSocketSession> sessions : localSessionManager.userSessions.values()) {
|
||||||
for (WebSocketSession session : sessions) {
|
for (WebSocketSession session : sessions) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user