feat(config): 增加PowerJobWorker端口配置支持
- 从属性文件读取powerjob.worker.port配置项 - 将端口号设置为读取的配置值,替代随机生成 - 优化PowerJobWorker初始化,提升配置灵活性 - 修复配置类导入的无用scala.Int依赖问题
This commit is contained in:
parent
529ab9ac20
commit
c3738f4f55
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import scala.Int;
|
||||||
import tech.powerjob.common.enums.Protocol;
|
import tech.powerjob.common.enums.Protocol;
|
||||||
import tech.powerjob.worker.PowerJobSpringWorker;
|
import tech.powerjob.worker.PowerJobSpringWorker;
|
||||||
import tech.powerjob.worker.common.PowerJobWorkerConfig;
|
import tech.powerjob.worker.common.PowerJobWorkerConfig;
|
||||||
|
|
@ -19,11 +20,14 @@ public class PowerJobWorkerConfiguration {
|
||||||
@Value("${powerjob.worker.server-address}")
|
@Value("${powerjob.worker.server-address}")
|
||||||
private String severAddress;
|
private String severAddress;
|
||||||
|
|
||||||
|
@Value("${powerjob.worker.port}")
|
||||||
|
private int port;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PowerJobSpringWorker initPowerJobWorker() {
|
public PowerJobSpringWorker initPowerJobWorker() {
|
||||||
PowerJobWorkerConfig config = new PowerJobWorkerConfig();
|
PowerJobWorkerConfig config = new PowerJobWorkerConfig();
|
||||||
config.setAppName(appName);
|
config.setAppName(appName);
|
||||||
config.setPort(RandomUtil.randomInt(10000, 20000));
|
config.setPort(port);
|
||||||
config.setServerAddress(StrUtil.split(severAddress, ","));
|
config.setServerAddress(StrUtil.split(severAddress, ","));
|
||||||
config.setProtocol(Protocol.HTTP);
|
config.setProtocol(Protocol.HTTP);
|
||||||
// 如果没有大型 Map/MapReduce 的需求,建议使用内存来加速计算
|
// 如果没有大型 Map/MapReduce 的需求,建议使用内存来加速计算
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue