You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/10/08 12:49:02 UTC
[GitHub] [camel] davsclaus commented on a change in pull request #6232: CAMEL-17054 - Support headers in nats consumer/producer
davsclaus commented on a change in pull request #6232:
URL: https://github.com/apache/camel/pull/6232#discussion_r724980114
##########
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:
you need to use the header filter strategy here to filter and only include valid headers
##########
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:
The same header, filter only wanted headers via the strategy
--
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-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org