服务器地址获取

master
zhangshanxue 2019-09-16 15:42:06 +08:00
parent 1c1a761e0f
commit b39158fe67
3 changed files with 22 additions and 4 deletions

View File

@ -4,8 +4,10 @@ import com.jmfy.dao.ServerInfoDao;
import com.jmfy.dao.impl.NoticeInfoDaoImpl;
import com.jmfy.model.CServerOpenTime;
import com.jmfy.model.ServerInfo;
import com.jmfy.redisProperties.RedisUserKey;
import com.jmfy.thrift.idl.Result;
import com.jmfy.utils.RPCClient;
import com.jmfy.utils.RedisUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -48,9 +50,13 @@ public class MsgController {
continue;
}
try {
ServerInfo serverInfo = serverInfoDao.getServerinfo(Integer.valueOf(serverId));
// ServerInfo serverInfo = serverInfoDao.getServerinfo(Integer.valueOf(serverId));
//TODO 分服
String thriftIp = serverInfo.getIP();
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(serverId), String.class, -1);
if(null==rpcString){
throw new Exception("serverAddress not exist");
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = String.valueOf(7901);
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
return -1;

View File

@ -5,8 +5,10 @@ import com.jmfy.dao.ServerInfoDao;
import com.jmfy.dao.UserInfoDao;
import com.jmfy.model.CUserInfo;
import com.jmfy.model.ServerInfo;
import com.jmfy.redisProperties.RedisUserKey;
import com.jmfy.thrift.idl.Result;
import com.jmfy.utils.RPCClient;
import com.jmfy.utils.RedisUtil;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@ -107,7 +109,11 @@ public class GMHandler extends BaseHandler {
if (null == coreServerList) {
continue;
} else {
String thriftIp = coreServerList.getIP();
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(coreServerList.getServer_id()), String.class, -1);
if(null==rpcString){
continue;
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = String.valueOf(7901);
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
continue;
@ -130,7 +136,12 @@ public class GMHandler extends BaseHandler {
if (null == coreServerList) {
throw new Exception("应用不存在");
} else {
String thriftIp = coreServerList.getIP();
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, String.valueOf(coreServerList.getServer_id()), String.class, -1);
if(null==rpcString){
throw new Exception("serverAddress not exist");
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = String.valueOf(7900 + 1);
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
throw new Exception("serverAddress not exist");

View File

@ -18,6 +18,7 @@ public class RedisUserKey {
public static final String QUESTION_FROMBACK = "QUESTION_FROMBACK";
public static final String QUESTION_FROMBACK_ALL = "QUESTION_FROMBACK_ALL";//所有问卷
public static final String READY_TO_USER_MAIL = "READY_TO_USER_MAIL";
public static final String LOGIC_SERVER_INFO = "LOGIC_SERVER_INFO";
/**
* 线 updata/min