private static void load() throws Exception {
if (!isLoaded) {
_ip = getProperty("/mq/activemq/ip");
_port = getProperty("/mq/activemq/port");
isLoaded = true;
}
}
public static String getUrl() throws Exception {
load();
StringBuilder failover = new StringBuilder();
String[] ips = _ip.split(";"), ports = _port.split(";");
for (int i = 0; i < ips.length; ++i) {
failover.append("tcp://").append(ips[i]).append(":").append(ports[i]).append(",");
}
failover.setLength(failover.length() - 1);
String failovers = failover.toString();
if (ips.length > 1) {
failovers = "failover:(" + failovers + ")";
}
return failovers;
}
}
上面的代码需要解释的地方跟MQ相关的不多,主要就是如果是mq集群,则格式是:failover:(tcp://192.168.1.117:1001,tcp://192.168.1.118:1001,tcp://xxx.xxx.xxx.xxx:port)。其它上面代码没有对Zookeeper集群都挂了的情况,做应急连接方案。当然,无论如何本节都不是全文的重点,但是多学一技何尝不可?
推荐阅读:
Ubuntu下的ACTIVEMQ服务器
CentOS 6.5启动ActiveMQ报错解决
Spring+JMS+ActiveMQ+Tomcat实现消息服务