vineetsaurabh commented on code in PR #18212:
URL: https://github.com/apache/camel/pull/18212#discussion_r2123144504
##########
components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java:
##########
@@ -193,4 +195,65 @@ protected void doStop() throws Exception {
super.doStop();
}
+ private void publishWithJetStream(NatsConfiguration config, final byte[]
body, final Exchange exchange) {
+ LOG.debug("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("Failed to initialize JetStream: " +
e.getMessage(), e);
+ }
+
+ 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);
+ }
+ final Message jetStreamMessage = builder.build();
+
+ PublishAck pa;
+ if (config.isJetstreamAsync()) {
+ CompletableFuture<PublishAck> future =
js.publishAsync(jetStreamMessage);
+ try {
+ pa = future.get(1, TimeUnit.SECONDS);
Review Comment:
Changing it to `future.get(config.getRequestTimeout(),
TimeUnit.MILLISECONDS);`, which has a default value 20000L
--
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]