6.3. 配置故障切换
AMQ JavaScript 允许您以编程方式配置备用连接端点。
要指定多个连接端点,定义返回新连接选项并在 connection_details 选项中传递函数的功能。每次尝试连接时会调用一次函数。
示例:配置故障切换
var hosts = ["alpha.example.com", "beta.example.com"];
var index = -1;
function failover_fn() {
index += 1;
if (index == hosts.length) index = 0;
return {host: hosts[index].hostname};
};
var opts = {
host: "example.com",
connection_details: failover_fn
}
container.connect(opts);
此示例为主机列表实施重复循环故障转移。您可以使用这个接口来实施您自己的故障切换行为。