Skip to content

Commit 033a066

Browse files
committed
Log warning in case of unexpected use of dev mode
The dev mode is activated when no address resolver is set, the host is localhost, and the user is guest. The dev mode sets a resolver that always uses localhost, this avoids problems when e.g. the metadata frame returns the hostname of a local container that the client application cannot reach. This commit adds a warn-level log message if the client detects a local cluster setup (because there are several addresses passed in to the address resolver). References #420
1 parent 0710b97 commit 033a066

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/java/com/rabbitmq/stream/impl/StreamEnvironment.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
import java.net.URLDecoder;
4343
import java.time.Duration;
4444
import java.time.LocalDateTime;
45-
import java.util.Collections;
46-
import java.util.List;
47-
import java.util.Map;
48-
import java.util.Optional;
45+
import java.util.*;
4946
import java.util.concurrent.*;
5047
import java.util.concurrent.atomic.AtomicBoolean;
5148
import java.util.concurrent.atomic.AtomicReference;
@@ -159,7 +156,16 @@ class StreamEnvironment implements Environment {
159156
String username = ((UsernamePasswordCredentialsProvider) credentialsProvider).getUsername();
160157
if (DEFAULT_USERNAME.equals(username)) {
161158
Address address = new Address("localhost", clientParametersPrototype.port());
162-
addressResolverToUse = ignored -> address;
159+
Set<Address> passedInAddresses = ConcurrentHashMap.newKeySet();
160+
addressResolverToUse =
161+
addr -> {
162+
passedInAddresses.add(addr);
163+
if (passedInAddresses.size() > 1) {
164+
LOGGER.warn("Assumed development environment but it seems incorrect.");
165+
passedInAddresses.clear();
166+
}
167+
return address;
168+
};
163169
LOGGER.info(
164170
"Connecting to localhost with {} user, assuming development environment",
165171
DEFAULT_USERNAME);

0 commit comments

Comments
 (0)