davsclaus commented on code in PR #30736:
URL: https://github.com/apache/camel/pull/30736#discussion_r4684169930
##########
components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java:
##########
@@ -180,6 +187,84 @@ protected void doStart() throws Exception {
this.connection =
this.getEndpoint().getConfiguration().getConnection() != null
? this.getEndpoint().getConfiguration().getConnection()
: this.getEndpoint().getConnection();
+
+ final NatsConfiguration config = this.getEndpoint().getConfiguration();
+ final ServerInfo serverInfo = this.connection.getServerInfo();
+ // a restarted producer has a new connection
+ this.jetStream = null;
+ if (config.isJetstreamEnabled() && serverInfo != null &&
serverInfo.isJetStreamAvailable()) {
+ // the JetStream context belongs to the connection, which stays
the same object when jnats reconnects
+ this.jetStream = createJetStream(config);
+ if (ObjectHelper.isNotEmpty(config.getJetstreamName())) {
+ ensureStream(config);
+ }
+ }
+ }
+
+ private JetStream createJetStream(NatsConfiguration config) throws
IOException {
+ // jnats uses its own request timeout (the connection timeout) for the
acknowledgement of a publish, unless the
+ // JetStream context has one
+ final JetStreamOptions.Builder options = JetStreamOptions.builder();
+ if (config.getRequestTimeout() > 0) {
+
options.requestTimeout(Duration.ofMillis(config.getRequestTimeout()));
+ }
+ return this.connection.jetStream(options.build());
+ }
+
+ private JetStream getJetStream(NatsConfiguration config) throws
IOException {
+ JetStream js = this.jetStream;
+ if (js == null) {
+ // JetStream was not available when the producer started
+ js = createJetStream(config);
+ this.jetStream = js;
+ }
+ return js;
+ }
Review Comment:
_Claude Code on behalf of davsclaus_
Done: the comment in `getJetStream` now says that two threads may both
create a JetStream context and that this does no harm. (d0bf96efa9ca)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]