mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[dev] no longer use random akka port
This commit is contained in:
parent
f06ae8be8f
commit
4981af0e26
@ -7,6 +7,7 @@ import com.github.kfcfans.oms.common.RemoteConstant;
|
|||||||
import com.github.kfcfans.oms.common.utils.NetUtils;
|
import com.github.kfcfans.oms.common.utils.NetUtils;
|
||||||
import com.github.kfcfans.oms.server.akka.actors.FriendActor;
|
import com.github.kfcfans.oms.server.akka.actors.FriendActor;
|
||||||
import com.github.kfcfans.oms.server.akka.actors.ServerActor;
|
import com.github.kfcfans.oms.server.akka.actors.ServerActor;
|
||||||
|
import com.github.kfcfans.oms.server.common.utils.PropertyUtils;
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.typesafe.config.Config;
|
import com.typesafe.config.Config;
|
||||||
@ -15,6 +16,7 @@ import lombok.Getter;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务端 ActorSystem 启动器
|
* 服务端 ActorSystem 启动器
|
||||||
@ -35,10 +37,15 @@ public class OhMyServer {
|
|||||||
|
|
||||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
log.info("[OhMyServer] OhMyServer's akka system start to bootstrap...");
|
log.info("[OhMyServer] OhMyServer's akka system start to bootstrap...");
|
||||||
|
|
||||||
|
// 1. 解析配置文件
|
||||||
|
PropertyUtils.init();
|
||||||
|
Properties properties = PropertyUtils.getProperties();
|
||||||
|
int port = Integer.parseInt(properties.getProperty("oms.akka.port", "10086"));
|
||||||
|
|
||||||
// 1. 启动 ActorSystem
|
// 1. 启动 ActorSystem
|
||||||
Map<String, Object> overrideConfig = Maps.newHashMap();
|
Map<String, Object> overrideConfig = Maps.newHashMap();
|
||||||
String localIP = NetUtils.getLocalHost();
|
String localIP = NetUtils.getLocalHost();
|
||||||
int port = NetUtils.getAvailablePort();
|
|
||||||
overrideConfig.put("akka.remote.artery.canonical.hostname", localIP);
|
overrideConfig.put("akka.remote.artery.canonical.hostname", localIP);
|
||||||
overrideConfig.put("akka.remote.artery.canonical.port", port);
|
overrideConfig.put("akka.remote.artery.canonical.port", port);
|
||||||
actorSystemAddress = localIP + ":" + port;
|
actorSystemAddress = localIP + ":" + port;
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.github.kfcfans.oms.server.common.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载配置文件
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2020/5/18
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class PropertyUtils {
|
||||||
|
|
||||||
|
private static final Properties PROPERTIES = new Properties();
|
||||||
|
|
||||||
|
public static Properties getProperties() {
|
||||||
|
return PROPERTIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
URL propertiesURL =PropertyUtils.class.getClassLoader().getResource("application.properties");
|
||||||
|
Objects.requireNonNull(propertiesURL);
|
||||||
|
try (InputStream is = propertiesURL.openStream()) {
|
||||||
|
PROPERTIES.load(is);
|
||||||
|
}catch (Exception e) {
|
||||||
|
ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user