You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/04 07:29:56 UTC
[camel] 02/02: camel-nats - Let producer use byte[] if possible
instead of string as first choice
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 199b16729dabc9493e80b780af98ccb3f6e60fe7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 4 08:29:34 2019 +0100
camel-nats - Let producer use byte[] if possible instead of string as first choice
---
.../java/org/apache/camel/component/nats/NatsProducer.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java
index a46eaff..764a7a5 100644
--- a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java
+++ b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsProducer.java
@@ -40,15 +40,19 @@ public class NatsProducer extends DefaultProducer {
@Override
public void process(Exchange exchange) throws Exception {
NatsConfiguration config = getEndpoint().getConfiguration();
- String body = exchange.getIn().getMandatoryBody(String.class);
+ byte[] body = exchange.getIn().getBody(byte[].class);
+ if (body == null) {
+ // fallback to use string
+ body = exchange.getIn().getMandatoryBody(String.class).getBytes();
+ }
log.debug("Publishing to topic: {}", config.getTopic());
if (ObjectHelper.isNotEmpty(config.getReplySubject())) {
String replySubject = config.getReplySubject();
- connection.publish(config.getTopic(), replySubject, body.getBytes());
+ connection.publish(config.getTopic(), replySubject, body);
} else {
- connection.publish(config.getTopic(), body.getBytes());
+ connection.publish(config.getTopic(), body);
}
}