jameshilliard commented on a change in pull request #5034: URL: https://github.com/apache/camel/pull/5034#discussion_r571459117
########## File path: components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java ########## @@ -42,21 +47,42 @@ public NatsEndpoint getEndpoint() { } @Override - public void process(Exchange exchange) throws Exception { + public void process(Exchange exchange) { NatsConfiguration config = getEndpoint().getConfiguration(); byte[] body = exchange.getIn().getBody(byte[].class); if (body == null) { - // fallback to use string - body = exchange.getIn().getMandatoryBody(String.class).getBytes(); + try { + // fallback to use string + body = exchange.getIn().getMandatoryBody(String.class).getBytes(); + } catch (InvalidPayloadException e) { + exchange.setException(e); + } } - LOG.debug("Publishing to topic: {}", config.getTopic()); + if (exchange.getPattern().isOutCapable()) { + LOG.debug("Requesting to topic: {}", config.getTopic()); - if (ObjectHelper.isNotEmpty(config.getReplySubject())) { - String replySubject = config.getReplySubject(); - connection.publish(config.getTopic(), replySubject, body); + CompletableFuture<io.nats.client.Message> future = connection.request(config.getTopic(), body); Review comment: > Here is an opportunity to use correct asynchronous by switching over to Camel's process(exchange, callback) where we can the continue the callback when the completable future has a response I wasn't exactly sure how I should style that, is there another implementation I should try and model it after? > btw does `connection.request` automatic use some sort of temporary request/reply mechanism? Yeah, the nats library handles it internally with a sort of temporary single reply subscription from my understanding. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org