修改打包环境
This commit is contained in:
@@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
|
||||
@ConfigurationProperties(prefix = "appconfig")
|
||||
public class AppConfig {
|
||||
|
||||
|
||||
private String privateKey;
|
||||
|
||||
/** zk连接地址*/
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.lld.im.common.enums.RouteHashMethodEnum;
|
||||
import com.lld.im.common.route.RouteHandle;
|
||||
import com.lld.im.common.route.algorithm.consistenthash.AbstractConsistentHash;
|
||||
import com.lld.im.service.utils.SnowflakeIdWorker;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.I0Itec.zkclient.ZkClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -18,6 +19,7 @@ import java.lang.reflect.Method;
|
||||
* @author: lld
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class BeanConfig {
|
||||
|
||||
@@ -26,6 +28,10 @@ public class BeanConfig {
|
||||
|
||||
@Bean
|
||||
public ZkClient buildZKClient() {
|
||||
log.info("================================================zkclient================================================");
|
||||
log.info("================================================zkclient================================================");
|
||||
log.info("================================================zkclient================================================");
|
||||
log.info(appConfig.getZkAddr());
|
||||
return new ZkClient(appConfig.getZkAddr(),
|
||||
appConfig.getZkConnectTimeOut());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.lld.im.service.user.controller;
|
||||
|
||||
import com.lld.im.common.ClientType;
|
||||
import com.lld.im.common.ResponseVO;
|
||||
import com.lld.im.common.config.AppConfig;
|
||||
import com.lld.im.common.route.RouteHandle;
|
||||
import com.lld.im.common.route.RouteInfo;
|
||||
import com.lld.im.common.utils.RouteInfoParseUtil;
|
||||
@@ -28,6 +29,9 @@ import java.util.List;
|
||||
@RequestMapping("v1/user")
|
||||
@Slf4j
|
||||
public class ImUserController {
|
||||
@Autowired
|
||||
AppConfig appConfig;
|
||||
|
||||
@Autowired
|
||||
ImUserService imUserService;
|
||||
|
||||
@@ -73,7 +77,10 @@ public class ImUserController {
|
||||
}
|
||||
String s = routeHandle.routeServer(allNode, req
|
||||
.getUserId());
|
||||
|
||||
|
||||
RouteInfo parse = RouteInfoParseUtil.parse(s);
|
||||
|
||||
return ResponseVO.successResponse(parse);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: beAs0LHX2GyTxMw4
|
||||
url: jdbc:mysql://43.139.191.204:3306:3306/im-core?serverTimezone=UTC&useSSL=false&characterEncoding=UTF8
|
||||
url: jdbc:mysql://43.139.191.204:3306/im-core?serverTimezone=UTC&useSSL=false&characterEncoding=UTF8
|
||||
username: root
|
||||
|
||||
redis:
|
||||
|
||||
@@ -19,7 +19,10 @@ import org.yaml.snakeyaml.Yaml;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@@ -60,15 +63,43 @@ public class StarterServer implements ApplicationRunner {
|
||||
|
||||
|
||||
|
||||
private void registerZK(BootstrapConfig config) throws UnknownHostException {
|
||||
String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
private void registerZK(BootstrapConfig config) throws Exception {
|
||||
String hostAddress = this.getIpAdd();
|
||||
//TODO 后面优化
|
||||
String ip = System.getenv("IM_HOST");
|
||||
ZkClient zkClient = new ZkClient(config.getLim().getZkConfig().getZkAddr(),
|
||||
config.getLim().getZkConfig().getZkConnectTimeOut());
|
||||
ZKit zKit = new ZKit(zkClient);
|
||||
RegistryZK registryZK = new RegistryZK(zKit, hostAddress, config.getLim());
|
||||
RegistryZK registryZK = new RegistryZK(zKit, ip, config.getLim());
|
||||
Thread thread = new Thread(registryZK);
|
||||
thread.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getIpAdd() throws SocketException, UnknownHostException{
|
||||
String ip="";
|
||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||
NetworkInterface intf = en.nextElement();
|
||||
String name = intf.getName();
|
||||
if (!name.contains("docker") && !name.contains("lo")) {
|
||||
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
|
||||
//获得IP
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress()) {
|
||||
String ipaddress = inetAddress.getHostAddress().toString();
|
||||
if (!ipaddress.contains("::") && !ipaddress.contains("0:0:") && !ipaddress.contains("fe80")) {
|
||||
|
||||
System.out.println(ipaddress);
|
||||
if(!"127.0.0.1".equals(ip)){
|
||||
ip = ipaddress;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
lim:
|
||||
host: 119.45.242.222
|
||||
tcpPort: 29000
|
||||
webSocketPort: 29001
|
||||
bossThreadSize: 1
|
||||
@@ -25,9 +26,9 @@ lim:
|
||||
rabbitmq:
|
||||
host: 119.45.242.222
|
||||
port: 5672
|
||||
addresses: 119.45.242.222
|
||||
username: guest
|
||||
password: guest
|
||||
virtualHost: /
|
||||
userName: guest
|
||||
passWord: guest
|
||||
|
||||
zkConfig:
|
||||
zkAddr: 119.45.242.222:2181
|
||||
|
||||
Reference in New Issue
Block a user