[英]Load Balancing LDAP Connection in Spring
我有两个希望以循环方式使用的LDAP服务器。 这样编写的代码似乎总是选择第一个服务器。 如何获得均匀选择的信息 ?
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模板:
SearchControls searchControls = new SearchControls();
searchControls.setTimeLimit(5000);
List ldapResultList = ldapTemplate.search("", filter.encode(), searchControls, (ContextMapper) o -> {
// do things with result...
});
查看spring-ldap参考文档 :
如果需要故障转移功能,则可以指定多个URL
因此,您将无法通过这种方式实现负载平衡。
如果要在不同的LDAP服务器之间进行负载平衡,则应该使用指向位于LDAP服务器前面的负载均衡器(例如HaProxy )的单个LDAP服务器URL,并将其与mode tcp
一起使用,然后使用balance roundrobin
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.