Kaynağa Gözat

message-service 中使用 NODE_ADDRESS 代替 SERVER_ADDRESS 来指定节点的地址, SERVER_ADDRESS 是关键字, 使用 SERVER_ADDRESS 时服务监听端口时会绑定该地址, 而不是监听所有地址

reghao 2 ay önce
ebeveyn
işleme
93c4802360

+ 3 - 2
message/message-service/src/main/java/cn/reghao/tnb/message/app/config/SpringLifecycle.java

@@ -32,8 +32,9 @@ public class SpringLifecycle implements ApplicationRunner, DisposableBean {
         Set<String> ipv4AddressSet = getAddress();
         // 通过 vm option -Dserver.address=192.168.0.10 指定
         String serverAddress1 = System.getProperty("server.address");
-        // 通过环境变量 SERVER_ADDRESS=192.168.0.10 指定
-        String serverAddress = System.getenv("SERVER_ADDRESS");
+        // 通过环境变量 SERVER_ADDRESS=192.168.0.10 指定时端口会绑定到该地址, 只会监听 192.168.0.10:6002
+        // 通过环境变量 NODE_ADDRESS=192.168.0.10 指定
+        String serverAddress = System.getenv("NODE_ADDRESS");
         if (!ipv4AddressSet.contains(serverAddress)) {
             log.error("没有通过环境变量 SERVER_ADDRESS 指定地址, 或是指定的地址不是机器地址 {}, 结束 MessageService 进程...", ipv4AddressSet);
             System.exit(SpringApplication.exit(applicationContext));