Skip to content

Commit

Permalink
connSrv增加权重等扩展属性配置
Browse files Browse the repository at this point in the history
  • Loading branch information
夜色 committed Jul 24, 2017
1 parent a4297af commit 9cc3974
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
6 changes: 4 additions & 2 deletions conf/reference.conf
Expand Up @@ -40,13 +40,15 @@ mp {


#网络配置 #网络配置
net { net {

local-ip="" //本地ip, 默认取第一个网卡 local-ip="" //本地ip, 默认取第一个网卡
public-ip="" //外网ip, 默认取第一个网卡 public-ip="" //外网ip, 默认取第一个网卡


connect-server-bind-ip="" //connSrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0) connect-server-bind-ip="" //connSrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)
connect-server-register-ip=${mp.net.public-ip} //公网ip, 注册到zk中的ip, 默认是public-ip connect-server-register-ip=${mp.net.public-ip} //公网ip, 注册到zk中的ip, 默认是public-ip
connect-server-port=3000 //长链接服务对外端口, 公网端口 connect-server-port=3000 //长链接服务对外端口, 公网端口
connect-server-register-attr { //注册到zk里的额外属性,比如配置权重,可在alloc里排序
weight:1
}


gateway-server-bind-ip="" //gatewaySrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0) gateway-server-bind-ip="" //gatewaySrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)
gateway-server-register-ip=${mp.net.local-ip} //本地ip, 注册到zk中的ip, 默认是local-ip gateway-server-register-ip=${mp.net.local-ip} //本地ip, 注册到zk中的ip, 默认是local-ip
Expand All @@ -62,7 +64,7 @@ mp {
ws-server-port=0 //websocket对外端口, 公网端口, 0表示禁用websocket ws-server-port=0 //websocket对外端口, 公网端口, 0表示禁用websocket
ws-path="/" //websocket path ws-path="/" //websocket path


public-host-mapping { //本机局域网IP和公网IP的映射关系 public-host-mapping { //本机局域网IP和公网IP的映射关系, 该配置后续会被废弃
//"10.0.10.156":"111.1.32.137" //"10.0.10.156":"111.1.32.137"
//"10.0.10.166":"111.1.33.138" //"10.0.10.166":"111.1.33.138"
} }
Expand Down
13 changes: 7 additions & 6 deletions mpush-api/src/main/java/com/mpush/api/srd/CommonServiceNode.java
Expand Up @@ -34,7 +34,7 @@ public final class CommonServiceNode implements ServiceNode {


private int port; private int port;


private Map<String, String> attrs; private Map<String, Object> attrs;


private transient String name; private transient String name;


Expand All @@ -58,18 +58,19 @@ public void setServiceName(String name) {
this.name = name; this.name = name;
} }


public CommonServiceNode addAttr(String name, String value) { public CommonServiceNode addAttr(String name, Object value) {
if (attrs == null) attrs = new HashMap<>(); if (attrs == null) attrs = new HashMap<>();
attrs.put(name, value); attrs.put(name, value);
return this; return this;
} }


@SuppressWarnings("unchecked")
@Override @Override
public String getAttr(String name) { public <T> T getAttr(String name) {
if (attrs == null || attrs.isEmpty()) { if (attrs == null || attrs.isEmpty()) {
return null; return null;
} }
return attrs.get(name); return (T) attrs.get(name);
} }


@Override @Override
Expand Down Expand Up @@ -105,11 +106,11 @@ public int getPort() {
return port; return port;
} }


public Map<String, String> getAttrs() { public Map<String, Object> getAttrs() {
return attrs; return attrs;
} }


public void setAttrs(Map<String, String> attrs) { public void setAttrs(Map<String, Object> attrs) {
this.attrs = attrs; this.attrs = attrs;
} }


Expand Down
2 changes: 1 addition & 1 deletion mpush-api/src/main/java/com/mpush/api/srd/ServiceNode.java
Expand Up @@ -34,7 +34,7 @@ public interface ServiceNode {


int getPort(); int getPort();


default String getAttr(String name) { default <T> T getAttr(String name) {
return null; return null;
} }


Expand Down
Expand Up @@ -40,7 +40,7 @@ public static ServiceNode cs() {
node.setPort(CC.mp.net.connect_server_port); node.setPort(CC.mp.net.connect_server_port);
node.setPersistent(false); node.setPersistent(false);
node.setServiceName(ServiceNames.CONN_SERVER); node.setServiceName(ServiceNames.CONN_SERVER);
//node.addAttr(ATTR_PUBLIC_IP, ConfigTools.getPublicIp()); node.setAttrs(CC.mp.net.connect_server_register_attr);
return node; return node;
} }


Expand Down
16 changes: 7 additions & 9 deletions mpush-tools/src/main/java/com/mpush/tools/config/CC.java
Expand Up @@ -88,18 +88,22 @@ interface net {
String local_ip = cfg.getString("local-ip"); String local_ip = cfg.getString("local-ip");
String public_ip = cfg.getString("public-ip"); String public_ip = cfg.getString("public-ip");


int connect_server_port = cfg.getInt("connect-server-port");
String connect_server_bind_ip = cfg.getString("connect-server-bind-ip"); String connect_server_bind_ip = cfg.getString("connect-server-bind-ip");
String connect_server_register_ip = cfg.getString("connect-server-register-ip"); String connect_server_register_ip = cfg.getString("connect-server-register-ip");
int connect_server_port = cfg.getInt("connect-server-port"); Map<String, Object> connect_server_register_attr = cfg.getObject("connect-server-register-attr").unwrapped();
int gateway_server_port = cfg.getInt("gateway-server-port");

int admin_server_port = cfg.getInt("admin-server-port"); int admin_server_port = cfg.getInt("admin-server-port");
int gateway_client_port = cfg.getInt("gateway-client-port");


int gateway_server_port = cfg.getInt("gateway-server-port");
String gateway_server_bind_ip = cfg.getString("gateway-server-bind-ip"); String gateway_server_bind_ip = cfg.getString("gateway-server-bind-ip");
String gateway_server_register_ip = cfg.getString("gateway-server-register-ip"); String gateway_server_register_ip = cfg.getString("gateway-server-register-ip");
String gateway_server_net = cfg.getString("gateway-server-net"); String gateway_server_net = cfg.getString("gateway-server-net");
String gateway_server_multicast = cfg.getString("gateway-server-multicast"); String gateway_server_multicast = cfg.getString("gateway-server-multicast");
String gateway_client_multicast = cfg.getString("gateway-client-multicast"); String gateway_client_multicast = cfg.getString("gateway-client-multicast");
int gateway_client_port = cfg.getInt("gateway-client-port");

int ws_server_port = cfg.getInt("ws-server-port"); int ws_server_port = cfg.getInt("ws-server-port");
String ws_path = cfg.getString("ws-path"); String ws_path = cfg.getString("ws-path");
int gateway_client_num = cfg.getInt("gateway-client-num"); int gateway_client_num = cfg.getInt("gateway-client-num");
Expand Down Expand Up @@ -347,11 +351,5 @@ interface monitor {
boolean profile_enabled = cfg.getBoolean("profile-enabled"); boolean profile_enabled = cfg.getBoolean("profile-enabled");
Duration profile_slowly_duration = cfg.getDuration("profile-slowly-duration"); Duration profile_slowly_duration = cfg.getDuration("profile-slowly-duration");
} }

interface spi {
Config cfg = mp.cfg.getObject("spi").toConfig();
String thread_pool_factory = cfg.getString("thread-pool-factory");
String dns_mapping_manager = cfg.getString("dns-mapping-manager");
}
} }
} }

0 comments on commit 9cc3974

Please sign in to comment.