修改: 合并 zhub 配置,addr="host:port", 去除原有 port参数
This commit is contained in:
parent
6e8e367b18
commit
3d4186ca65
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<zhubs>
|
<zhubs>
|
||||||
<!--<zhub name="zhub" addr="47.111.150.118" port="6066" groupid="group-zhub"/>-->
|
<!--<zhub name="zhub" addr="47.111.150.118" port="6066" groupid="group-zhub"/>-->
|
||||||
<zhub name="zhub" addr="127.0.0.1" port="1216" groupid="group-zhub"/>
|
<zhub name="zhub" addr="127.0.0.1:1216" groupid="group-zhub"/>
|
||||||
</zhubs>
|
</zhubs>
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -35,11 +35,11 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
public Logger logger = Logger.getLogger(ZHubClient.class.getSimpleName());
|
public Logger logger = Logger.getLogger(ZHubClient.class.getSimpleName());
|
||||||
|
|
||||||
@Resource(name = "property.zhub.host")
|
@Resource(name = "property.zhub.host")
|
||||||
private String host = "127.0.0.1";
|
private String addr = "127.0.0.1:1216";
|
||||||
@Resource(name = "property.zhub.password")
|
@Resource(name = "property.zhub.password")
|
||||||
private String password = "";
|
private String password = "";
|
||||||
@Resource(name = "property.zhub.port")
|
/*@Resource(name = "property.zhub.port")
|
||||||
private int port = 1216;
|
private int port = 1216;*/
|
||||||
@Resource(name = "property.zhub.groupid")
|
@Resource(name = "property.zhub.groupid")
|
||||||
private String groupid = "";
|
private String groupid = "";
|
||||||
|
|
||||||
@ -72,8 +72,14 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
|
|
||||||
// 自动注入
|
// 自动注入
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
host = config.getValue("addr", host);
|
addr = config.getValue("addr", addr);
|
||||||
port = config.getIntValue("port", port);
|
|
||||||
|
// 合并 addr = host:port, 做历史兼容
|
||||||
|
int port = config.getIntValue("port", 0);
|
||||||
|
if (port != 0 && !addr.contains(":")) {
|
||||||
|
addr = addr + ":" + port;
|
||||||
|
}
|
||||||
|
|
||||||
groupid = config.getValue("groupid", groupid);
|
groupid = config.getValue("groupid", groupid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,8 +88,8 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
isMain = true;
|
isMain = true;
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
}*/
|
}*/
|
||||||
if (!mainHub.containsKey(host + ":" + port)) { // 确保同步执行此 init 逻辑
|
if (!mainHub.containsKey(addr)) { // 确保同步执行此 init 逻辑
|
||||||
mainHub.put(host + ":" + port, this);
|
mainHub.put(addr, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initSocket(0)) {
|
if (!initSocket(0)) {
|
||||||
@ -330,6 +336,10 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
protected boolean initSocket(int retry) {
|
protected boolean initSocket(int retry) {
|
||||||
for (int i = 0; i <= retry; i++) {
|
for (int i = 0; i <= retry; i++) {
|
||||||
try {
|
try {
|
||||||
|
String[] hostPort = addr.split(":");
|
||||||
|
String host = hostPort[0];
|
||||||
|
int port = Integer.parseInt(hostPort[1]);
|
||||||
|
|
||||||
client = new Socket();
|
client = new Socket();
|
||||||
client.connect(new InetSocketAddress(host, port));
|
client.connect(new InetSocketAddress(host, port));
|
||||||
client.setKeepAlive(true);
|
client.setKeepAlive(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user