OpenGuidou commented on a change in pull request #6232:
URL: https://github.com/apache/camel/pull/6232#discussion_r725068227



##########
File path: 
components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java
##########
@@ -99,20 +108,42 @@ 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.getIn().getHeaders()));
+
             if (ObjectHelper.isNotEmpty(config.getReplySubject())) {
-                String replySubject = config.getReplySubject();
-                connection.publish(config.getTopic(), replySubject, body);
-            } else {
-                connection.publish(config.getTopic(), body);
+                final String replySubject = config.getReplySubject();
+                builder.replyTo(replySubject);
             }
+            this.connection.publish(builder.build());
             callback.done(true);
             return true;
         }
     }
 
+    private Headers buildHeaders(Map<String, Object> headersMap) {

Review comment:
       updated

##########
File path: 
components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
##########
@@ -153,31 +158,35 @@ public void run() {
             @Override
             public void onMessage(Message msg) throws InterruptedException {
                 LOG.debug("Received Message: {}", msg);
-                Exchange exchange = createExchange(false);
+                final Exchange exchange = 
NatsConsumer.this.createExchange(false);
                 try {
                     exchange.getIn().setBody(msg.getData());
                     exchange.getIn().setHeader(NatsConstants.NATS_REPLY_TO, 
msg.getReplyTo());
                     exchange.getIn().setHeader(NatsConstants.NATS_SID, 
msg.getSID());
                     exchange.getIn().setHeader(NatsConstants.NATS_SUBJECT, 
msg.getSubject());
                     exchange.getIn().setHeader(NatsConstants.NATS_QUEUE_NAME, 
msg.getSubscription().getQueueName());
                     
exchange.getIn().setHeader(NatsConstants.NATS_MESSAGE_TIMESTAMP, 
System.currentTimeMillis());
-
-                    processor.process(exchange);
+                    if (msg.getHeaders() != null) {

Review comment:
       updated




-- 
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


Reply via email to