2016-10-11 20 views
0

ラウンドロビン方式で使用する2つのLDAPサーバーがあります。このコードは、常に最初のサーバーを選択しているようです。 どうすれば均等に選ぶことができますか春のLDAP接続の負荷分散

SearchControls searchControls = new SearchControls(); 
searchControls.setTimeLimit(5000); 

List ldapResultList = ldapTemplate.search("", filter.encode(), searchControls, (ContextMapper) o -> { 
    // do things with result... 
}); 

答えて

1

チェックspring-ldap reference documentation

private static LdapTemplate createLdapTemplate(String[] urls, String username, String password) { 

    LdapContextSource contextSource = new LdapContextSource(); 
    contextSource.setUrls(urls); 
    contextSource.setBase(LDAP_SEARCH_BASE); 

    // username is the same for both LDAP servers 
    contextSource.setUserDn(username); 
    contextSource.setPassword(password); 

    contextSource.setPooled(true); 
    contextSource.afterPropertiesSet(); 

    return new LdapTemplate(contextSource); 
} 

は、私はLDAPテンプレートそうように使用フェイルオーバー機能が必要な場合は、複数のURLを指定することができます

このため、この方法でロードバランスを達成することはできません。

異なるLDAPサーバー間で負荷を分散する場合は、代わりにLDAPサーバーの前にロードバランサー(HaProxyなど)を指す単一のLDAPサーバーURLを使用して、mode tcp 、およびbalance roundrobin

関連する問題