Skip to content

Commit b9f2b3a

Browse files
committed
Apply Palantir Java Format
Assisted-By: Claude Code
1 parent 8e549d1 commit b9f2b3a

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

rqueue-nats/src/main/java/com/github/sonus21/rqueue/nats/internal/NatsProvisioner.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ private ConsumerInfo safeGetConsumerInfo(String streamName, String consumerName)
171171
try {
172172
return jsm.getConsumerInfo(streamName, consumerName);
173173
} catch (JetStreamApiException e) {
174-
if (e.getApiErrorCode() == 10014 || e.getErrorCode() == 404) {
174+
// 10014 = consumer not found, 10059 = stream not found (stream hasn't been created yet).
175+
// Both cases mean "consumer doesn't exist"; callers should create the consumer (and ensure
176+
// the stream) rather than receiving an exception here.
177+
if (e.getApiErrorCode() == 10014 || e.getApiErrorCode() == 10059 || e.getErrorCode() == 404) {
175178
return null;
176179
}
177180
throw e;

rqueue-nats/src/main/java/com/github/sonus21/rqueue/nats/js/NatsStreamValidator.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,21 @@ public void onApplicationEvent(RqueueBootstrapEvent event) {
109109
}
110110
}
111111
if (!failures.isEmpty()) {
112+
String hint = config.isAutoCreateStreams()
113+
? "Stream creation failed — verify NATS is running with JetStream enabled"
114+
+ " (start the server with `nats-server -js`) and that the account has"
115+
+ " `add_stream` permission."
116+
: "With rqueue.nats.auto-create-streams=false every required stream must exist"
117+
+ " before the application starts. Run `nats stream add` for each missing"
118+
+ " stream or set rqueue.nats.auto-create-streams=true to let rqueue create"
119+
+ " them automatically.";
112120
throw new IllegalStateException("NATS JetStream provisioning failed for "
113121
+ failures.size()
114122
+ " of "
115123
+ total
116-
+ " stream(s) at startup. With rqueue.nats.autoCreateStreams=false, every required"
117-
+ " stream must exist before the application starts. Failed streams:\n"
124+
+ " stream(s) at startup. "
125+
+ hint
126+
+ " Failed streams:\n"
118127
+ " - "
119128
+ String.join("\n - ", failures));
120129
}
@@ -129,7 +138,7 @@ private int tryEnsure(List<String> failures, String streamName, String subject)
129138
provisioner.ensureStream(streamName, List.of(subject));
130139
return 1;
131140
} catch (RqueueNatsException e) {
132-
failures.add(streamName + " (subject " + subject + "): " + e.getMessage());
141+
failures.add(streamName + " (subject " + subject + "): " + rootCause(e));
133142
return 1;
134143
}
135144
}
@@ -139,8 +148,18 @@ private int tryEnsureDlq(List<String> failures, String dlqStream, String dlqSubj
139148
provisioner.ensureDlqStream(dlqStream, List.of(dlqSubject));
140149
return 1;
141150
} catch (RqueueNatsException e) {
142-
failures.add(dlqStream + " (DLQ subject " + dlqSubject + "): " + e.getMessage());
151+
failures.add(dlqStream + " (DLQ subject " + dlqSubject + "): " + rootCause(e));
143152
return 1;
144153
}
145154
}
155+
156+
/** Returns the deepest non-null message in the cause chain for diagnostics. */
157+
private static String rootCause(Throwable t) {
158+
Throwable cause = t;
159+
while (cause.getCause() != null) {
160+
cause = cause.getCause();
161+
}
162+
String msg = cause.getMessage();
163+
return (msg != null && !msg.isEmpty()) ? msg : cause.getClass().getSimpleName();
164+
}
146165
}

rqueue-spring-boot-nats-example/src/main/java/com/github/sonus21/rqueue/example/RQueueNatApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
* pluggable-backend split.
3131
*/
3232
@SpringBootApplication
33-
public class RQueueApplication {
33+
public class RQueueNatApplication {
3434

3535
@Value("${workers.count:3}")
3636
private int workersCount;
3737

3838
public static void main(String[] args) {
39-
SpringApplication.run(RQueueApplication.class, args);
39+
SpringApplication.run(RQueueNatApplication.class, args);
4040
}
4141

4242
@Bean

rqueue-spring-boot-nats-example/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# enabled server. Everything else (queue names, listeners, controller) is
2020
# identical to the redis example, which is the point of the pluggable split.
2121
rqueue.backend=nats
22+
server.port=9090
2223

2324
# NATS / JetStream connection. Default is the public-binding nats-server URL
2425
# from a vanilla `nats-server -js` install. For docker, point at the running

0 commit comments

Comments
 (0)