Commit d98cc350 by Future

发消息优化

parent b7a5b582
......@@ -146,6 +146,18 @@
<artifactId>hutool-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.8</version>
</dependency>
</dependencies>
<!-- <build>-->
<!-- <resources>-->
......
......@@ -25,6 +25,7 @@ import com.wecloud.im.sdk.enums.ChatTypeEnum;
import com.wecloud.im.sdk.enums.FriendStateEnum;
import com.wecloud.im.sdk.enums.GroupRoleEnum;
import com.wecloud.im.sdk.enums.MutedEnum;
import com.wecloud.im.service.EhcacheService;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientBlacklistService;
import com.wecloud.im.service.ImClientService;
......@@ -98,7 +99,7 @@ public class NormalChatAction {
@Autowired
private ImFriendService friendService;
@Resource
private RedisUtils redisUtils;
private EhcacheService ehcacheService;
@ActionMapping("/normal/send")
@ApiOperation("普通消息发送")
......@@ -186,15 +187,7 @@ public class NormalChatAction {
imConversationMembersService.updateBatchById(tempMemberToUpdate);
}
}
String key = "push_" + conversation.getId();
String value = redisUtils.getKey(key);
final Boolean isPush;
if (StringUtils.isBlank(value)) {
isPush = Boolean.TRUE;
redisUtils.addKey(key, "1", Duration.ofMinutes(5));
} else {
isPush = Boolean.FALSE;
}
final Boolean isPush = ehcacheService.getIsPush(conversation.getId().toString());
// 多线程处理消息下发
for (ImConversationMembers member : membersList) {
if (member.getFkClientId().equals(imClientSender.getId())) {
......
package com.wecloud.im.service;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
/**
* @Author Future
* @Date 2022/8/24 17:18
* @Description 本地缓存服务
*/
@Slf4j
@Service
public class EhcacheService {
@Autowired
private CacheManager cacheManager;
/**
* 本地缓存中获取
* @param key
* @return
*/
public Boolean getIsPush(String key) {
Cache cache = cacheManager.getCache("push");
Object value = cache.get(key);
log.info("ehcache {}", JSON.toJSONString(value));
if (value != null) {
return false;
} else {
cache.put(key, 1);
return true;
}
}
}
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<cache name="push"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="300"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</cache>
</ehcache>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment