Skip to content

Commit 068c11a

Browse files
committed
Don't fail silently when the consumer can't connect. There was also a bug which prevented further reconnects. Fixes #17.
1 parent b38bf15 commit 068c11a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/com/github/brainlag/nsq/NSQConsumer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public NSQConsumer start() {
7171
//connect once otherwise we might have to wait one lookupPeriod
7272
connect();
7373
scheduler.scheduleAtFixedRate(() -> {
74-
connect();
74+
connect();
7575
}, lookupPeriod, lookupPeriod, TimeUnit.MILLISECONDS);
7676
}
7777
return this;
@@ -88,6 +88,7 @@ private Connection createConnection(final ServerAddress serverAddress) {
8888

8989
return connection;
9090
} catch (final NoConnectionsException e) {
91+
LogManager.getLogger(this).warn("Could not create connection to server {}", serverAddress.toString(), e);
9192
return null;
9293
}
9394
}
@@ -205,7 +206,10 @@ private void connect() {
205206

206207
for (final ServerAddress server : Sets.difference(newAddresses, oldAddresses)) {
207208
if (!connections.containsKey(server)) {
208-
connections.put(server, createConnection(server));
209+
final Connection connection = createConnection(server);
210+
if (connection != null) {
211+
connections.put(server, connection);
212+
}
209213
}
210214
}
211215
}

0 commit comments

Comments
 (0)