ramu11 commented on code in PR #25905:
URL: https://github.com/apache/camel/pull/25905#discussion_r3893473958


##########
components/camel-hivemq/src/main/java/org/apache/camel/component/hivemq/HiveMQProducer.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hivemq;
+
+import com.hivemq.client.mqtt.datatypes.MqttQos;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient;
+import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Exchange;
+import org.apache.camel.support.DefaultAsyncProducer;
+
+public class HiveMQProducer extends DefaultAsyncProducer {
+
+    private final HiveMQEndpoint endpoint;
+    private Mqtt5AsyncClient client;
+
+    public HiveMQProducer(HiveMQEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        client = endpoint.createClient();
+        client.connect().join();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (client != null && client.getState().isConnected()) {
+            client.disconnect().join();
+        }
+        super.doStop();
+    }
+
+    @Override
+    public boolean process(Exchange exchange, AsyncCallback callback) {
+        String targetTopic = 
exchange.getIn().getHeader(HiveMQConstants.OVERRIDE_TOPIC, endpoint.getTopic(), 
String.class);
+        MqttQos qos = exchange.getIn().getHeader(HiveMQConstants.MQTT_QOS, 
endpoint.getConfiguration().getQos(), MqttQos.class);
+        boolean retained = 
exchange.getIn().getHeader(HiveMQConstants.MQTT_RETAINED, 
endpoint.getConfiguration().isRetained(),
+                Boolean.class);
+
+        byte[] payload = exchange.getIn().getBody(byte[].class);

Review Comment:
   Addressed. A null Camel body is explicitly converted to an empty MQTT 
payload before publishing. Added HiveMQEmptyPayloadIT to verify that a null 
body results in an empty MQTT payload on the consumer side. No further changes 
are required.



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

Reply via email to