davsclaus commented on code in PR #18212: URL: https://github.com/apache/camel/pull/18212#discussion_r2121138794
########## components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java: ########## @@ -108,16 +108,53 @@ public boolean process(Exchange exchange, AsyncCallback callback) { } else { LOG.debug("Publishing to topic: {}", config.getTopic()); - final NatsMessage.Builder builder = NatsMessage.builder() - .data(body) - .subject(config.getTopic()) - .headers(this.buildHeaders(exchange)); - - if (ObjectHelper.isNotEmpty(config.getReplySubject())) { - final String replySubject = config.getReplySubject(); - builder.replyTo(replySubject); + if (config.isJetstreamEnabled() && this.connection.getServerInfo().isJetStreamAvailable()) { + LOG.info("JetStream is available"); + + JetStreamManagement jsm; + JetStream js; + try { + jsm = this.connection.jetStreamManagement(); + js = jsm.jetStream(); + if(js == null) { + jsm.addStream(StreamConfiguration.builder() + .name(config.getJetstreamName()) + .subjects(config.getTopic()) + .build()); + js = jsm.jetStream(); + } + } catch (IOException | JetStreamApiException e) { + throw new RuntimeException(e); + } + PublishAck pa; + if (config.isJetstreamAsync()) { + CompletableFuture<PublishAck> future = js.publishAsync(config.getTopic(), body); + try { + pa = future.get(1, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + throw new RuntimeException(e); + } + LOG.info("Publish Sequence async: {}", pa.getSeqno()); + } else { + try { + pa = js.publish(config.getTopic(), body); + } catch (IOException | JetStreamApiException e) { + throw new RuntimeException(e); + } + LOG.info("Publish Sequence synchronously: {}", pa.getSeqno()); + } + } else { Review Comment: Break it up into 2 methods, so one is jetstream and the other is non jetstream and as-is today -- 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: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org