diff --git a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/BeanConfig.java b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/BeanConfig.java index 81b05c90..34329c2a 100644 --- a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/BeanConfig.java +++ b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/config/BeanConfig.java @@ -1,13 +1,16 @@ package com.crossoverjie.cim.route.config; +import com.crossoverjie.cim.common.core.proxy.RpcProxyManager; import com.crossoverjie.cim.common.metastore.MetaStore; import com.crossoverjie.cim.common.metastore.ZkConfiguration; import com.crossoverjie.cim.common.metastore.ZkMetaStoreImpl; import com.crossoverjie.cim.common.route.algorithm.RouteHandle; import com.crossoverjie.cim.common.route.algorithm.consistenthash.AbstractConsistentHash; +import com.crossoverjie.cim.server.api.ServerApi; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import okhttp3.OkHttpClient; import org.I0Itec.zkclient.ZkClient; @@ -35,7 +38,7 @@ public class BeanConfig { - @Autowired + @Resource private AppConfiguration appConfiguration; @@ -105,4 +108,9 @@ public RouteHandle buildRouteHandle() throws Exception { } } + + @Bean + public ServerApi serverApi(OkHttpClient okHttpClient) { + return RpcProxyManager.create(ServerApi.class, okHttpClient); + } } diff --git a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImpl.java b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImpl.java index b707f849..1c7104c1 100644 --- a/cim-forward-route/src/main/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImpl.java +++ b/cim-forward-route/src/main/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImpl.java @@ -14,6 +14,7 @@ import com.crossoverjie.cim.route.service.UserInfoCacheService; import com.crossoverjie.cim.server.api.ServerApi; import com.crossoverjie.cim.server.api.vo.req.SendMsgReqVO; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import okhttp3.OkHttpClient; import okhttp3.Response; @@ -46,15 +47,18 @@ @Service public class AccountServiceRedisImpl implements AccountService { - @Autowired + @Resource private RedisTemplate redisTemplate; - @Autowired + @Resource private UserInfoCacheService userInfoCacheService; - @Autowired + @Resource private OkHttpClient okHttpClient; + @Resource + private ServerApi serverApi; + @Override public RegisterInfoResVO register(RegisterInfoResVO info) { String key = ACCOUNT_PREFIX + info.getUserId(); @@ -153,7 +157,7 @@ public void pushMsg(CIMServerResVO cimServerResVO, long sendUserId, ChatReqVO gr CIMUserInfo cimUserInfo = userInfoCacheService.loadUserInfoByUserId(sendUserId); String url = "http://" + cimServerResVO.getIp() + ":" + cimServerResVO.getHttpPort(); - ServerApi serverApi = RpcProxyManager.create(ServerApi.class, okHttpClient); + SendMsgReqVO vo = new SendMsgReqVO(cimUserInfo.getUserName() + ":" + groupReqVO.getMsg(), groupReqVO.getUserId()); serverApi.sendMsg(vo, url); } diff --git a/cim-server/src/main/java/com/crossoverjie/cim/server/config/BeanConfig.java b/cim-server/src/main/java/com/crossoverjie/cim/server/config/BeanConfig.java index 728d5d72..63eedbf2 100644 --- a/cim-server/src/main/java/com/crossoverjie/cim/server/config/BeanConfig.java +++ b/cim-server/src/main/java/com/crossoverjie/cim/server/config/BeanConfig.java @@ -1,10 +1,13 @@ package com.crossoverjie.cim.server.config; import com.crossoverjie.cim.common.constant.Constants; +import com.crossoverjie.cim.common.core.proxy.RpcProxyManager; import com.crossoverjie.cim.common.metastore.MetaStore; import com.crossoverjie.cim.common.metastore.ZkConfiguration; import com.crossoverjie.cim.common.metastore.ZkMetaStoreImpl; import com.crossoverjie.cim.common.protocol.CIMRequestProto; +import com.crossoverjie.cim.route.api.RouteApi; +import jakarta.annotation.Resource; import okhttp3.OkHttpClient; import org.I0Itec.zkclient.ZkClient; import org.apache.curator.retry.ExponentialBackoffRetry; @@ -24,6 +27,9 @@ @Configuration public class BeanConfig { + @Resource + private AppConfiguration appConfiguration; + /** * http client * @return okHttp @@ -57,4 +63,9 @@ public CIMRequestProto.CIMReqProtocol heartBeat() { .build(); return heart; } + + @Bean + public RouteApi routeApi(OkHttpClient okHttpClient) { + return RpcProxyManager.create(RouteApi.class, appConfiguration.getRouteUrl(), okHttpClient); + } } diff --git a/cim-server/src/main/java/com/crossoverjie/cim/server/kit/RouteHandler.java b/cim-server/src/main/java/com/crossoverjie/cim/server/kit/RouteHandler.java index 3ca18a4b..58ac16c6 100644 --- a/cim-server/src/main/java/com/crossoverjie/cim/server/kit/RouteHandler.java +++ b/cim-server/src/main/java/com/crossoverjie/cim/server/kit/RouteHandler.java @@ -7,6 +7,7 @@ import com.crossoverjie.cim.server.config.AppConfiguration; import com.crossoverjie.cim.server.util.SessionSocketHolder; import io.netty.channel.socket.nio.NioSocketChannel; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import okhttp3.OkHttpClient; import okhttp3.Response; @@ -26,12 +27,15 @@ @Slf4j public class RouteHandler { - @Autowired + @Resource private OkHttpClient okHttpClient; - @Autowired + @Resource private AppConfiguration configuration; + @Resource + private RouteApi routeApi; + /** * 用户下线 * @@ -57,7 +61,6 @@ public void userOffLine(CIMUserInfo userInfo, NioSocketChannel channel) { * @throws IOException */ public void clearRouteInfo(CIMUserInfo userInfo) { - RouteApi routeApi = RpcProxyManager.create(RouteApi.class, configuration.getRouteUrl(), okHttpClient); ChatReqVO vo = new ChatReqVO(userInfo.getUserId(), userInfo.getUserName()); routeApi.offLine(vo); }