@@ -145,6 +145,12 @@ static short encodeResponseCode(Short code) {
145
145
}
146
146
147
147
static ClientFactory coordinatorClientFactory (StreamEnvironment environment ) {
148
+ String messageFormat =
149
+ "%s. %s. "
150
+ + "This may be due to the usage of a load balancer that makes topology discovery fail. "
151
+ + "Use a custom AddressResolver or the --load-balancer flag if using StreamPerfTest. "
152
+ + "See https://rabbitmq.github.io/rabbitmq-stream-java-client/stable/htmlsingle/#understanding-connection-logic "
153
+ + "and https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/#with-a-load-balancer." ;
148
154
return context -> {
149
155
ClientParameters parametersCopy = context .parameters ().duplicate ();
150
156
Address address = new Address (parametersCopy .host (), parametersCopy .port ());
@@ -159,20 +165,15 @@ static ClientFactory coordinatorClientFactory(StreamEnvironment environment) {
159
165
return Utils .connectToAdvertisedNodeClientFactory (
160
166
context .key (), context1 -> new Client (context1 .parameters ()))
161
167
.client (Utils .ClientFactoryContext .fromParameters (parametersCopy ).key (context .key ()));
168
+ } catch (TimeoutStreamException e ) {
169
+ throw new TimeoutStreamException (
170
+ format (messageFormat , e .getMessage (), e .getCause ().getMessage (), e .getCause ()));
162
171
} catch (StreamException e ) {
163
172
if (e .getCause () != null
164
173
&& (e .getCause () instanceof UnknownHostException
165
174
|| e .getCause () instanceof ConnectTimeoutException )) {
166
- String message =
167
- e .getMessage ()
168
- + ". "
169
- + e .getCause ().getMessage ()
170
- + ". "
171
- + "This may be due to the usage of a load balancer that makes topology discovery fail. "
172
- + "Use a custom AddressResolver or the --load-balancer flag if using StreamPerfTest. "
173
- + "See https://rabbitmq.github.io/rabbitmq-stream-java-client/stable/htmlsingle/#understanding-connection-logic "
174
- + "and https://blog.rabbitmq.com/posts/2021/07/connecting-to-streams/#with-a-load-balancer." ;
175
- throw new StreamException (message , e .getCause ());
175
+ throw new StreamException (
176
+ format (messageFormat , e .getMessage (), e .getCause ().getMessage ()), e .getCause ());
176
177
} else {
177
178
throw e ;
178
179
}
@@ -204,11 +205,11 @@ static ClientFactory connectToAdvertisedNodeClientFactory(
204
205
}
205
206
206
207
static Runnable namedRunnable (Runnable task , String format , Object ... args ) {
207
- return new NamedRunnable (String . format (format , args ), task );
208
+ return new NamedRunnable (format (format , args ), task );
208
209
}
209
210
210
211
static <T , R > Function <T , R > namedFunction (Function <T , R > task , String format , Object ... args ) {
211
- return new NamedFunction <>(String . format (format , args ), task );
212
+ return new NamedFunction <>(format (format , args ), task );
212
213
}
213
214
214
215
static <T > T callAndMaybeRetry (
@@ -325,7 +326,7 @@ public Client client(ClientFactoryContext context) {
325
326
try {
326
327
Thread .sleep (this .retryInterval .toMillis ());
327
328
} catch (InterruptedException e ) {
328
- Thread .interrupted ();
329
+ Thread .currentThread (). interrupt ();
329
330
return null ;
330
331
}
331
332
}
0 commit comments