If srvHost is set using the ClusterSettings builder then ClusterConnectionMode must also be set to Multiple. If srvHost is set then hosts will be populated to the default host and default port and ClusterConnectionMode gets defaulted to Single.
When creating a connection to cluster if ClusterConnectionMode is not set to Multiple then it's assumed as a SingleServerCluster and the srvHost value is ignored.
if (clusterSettings.getMode() == ClusterConnectionMode.SINGLE) { return new SingleServerCluster(clusterId, clusterSettings, serverFactory); } else if (clusterSettings.getMode() == ClusterConnectionMode.MULTIPLE) { if (clusterSettings.getSrvHost() == null) { return new MultiServerCluster(clusterId, clusterSettings, serverFactory); } else { return new DnsMultiServerCluster(clusterId, clusterSettings, serverFactory, dnsSrvRecordMonitorFactory); } }
When using a ConnectionString with the mongodb+srv this is already being done.
public Builder applyConnectionString(final ConnectionString connectionString) { if (connectionString.isSrvProtocol()){ mode(ClusterConnectionMode.MULTIPLE); srvHost(connectionString.getHosts().get(0)); }