6.3. フェイルオーバーの設定
AMQ JavaScript を使用すると、代わりの接続エンドポイントをプログラムで設定できます。
複数の接続エンドポイントを指定するには、新しい接続オプションを返す関数を定義し、connection_details オプションで関数を渡します。この関数は、接続試行ごとに 1 回呼び出されます。
例: フェイルオーバーの設定
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);
この例では、ホストの一覧に対してラウンドロビンフェイルオーバーを繰り返すように実装します。このインターフェイスを使用して、独自のフェイルオーバー動作を実装できます。