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


##########
components/camel-hivemq/src/main/java/org/apache/camel/component/hivemq/HiveMQEndpoint.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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 java.nio.charset.StandardCharsets;
+
+import com.hivemq.client.mqtt.MqttClient;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5ClientBuilder;
+import com.hivemq.client.mqtt.mqtt5.message.auth.Mqtt5SimpleAuth;
+import com.hivemq.client.mqtt.mqtt5.message.auth.Mqtt5SimpleAuthBuilder;
+import org.apache.camel.Category;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.EndpointServiceLocation;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultEndpoint;
+
+@UriEndpoint(firstVersion = "4.23.0", scheme = "hivemq", title = "HiveMQ", 
syntax = "hivemq:topic",
+             category = { Category.MESSAGING, Category.IOT }, headersClass = 
HiveMQConstants.class)
+public class HiveMQEndpoint extends DefaultEndpoint implements 
EndpointServiceLocation {
+
+    /**
+     * The MQTT topic name or pattern to subscribe to or publish on.
+     */
+    @UriPath
+    @Metadata(required = true)
+    private String topic;
+
+    /**
+     * The HiveMQ component configuration options.
+     */
+    @UriParam
+    @Metadata(description = "To use a custom HiveMQConfiguration")
+    private HiveMQConfiguration configuration;
+
+    public HiveMQEndpoint(String uri, HiveMQComponent component, 
HiveMQConfiguration configuration, String topic) {
+        super(uri, component);
+        this.configuration = configuration;
+        this.topic = topic;
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        return new HiveMQProducer(this);
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        HiveMQConsumer consumer = new HiveMQConsumer(this, processor);
+        configureConsumer(consumer);
+        return consumer;
+    }
+
+    public Mqtt5AsyncClient createClient() {
+        Mqtt5ClientBuilder builder = MqttClient.builder()
+                .serverHost(configuration.getHost())
+                .serverPort(configuration.getPort())
+                .automaticReconnectWithDefaultConfig()
+                .useMqttVersion5();
+
+        if (configuration.getClientId() != null) {
+            builder.identifier(configuration.getClientId());
+        }
+
+        if (configuration.isSsl()) {
+            builder.sslWithDefaultConfig();
+        }
+
+        if (configuration.getUsername() != null) {
+            Mqtt5SimpleAuthBuilder.Complete authBuilder
+                    = 
Mqtt5SimpleAuth.builder().username(configuration.getUsername());
+            if (configuration.getPassword() != null) {
+                
authBuilder.password(configuration.getPassword().getBytes(StandardCharsets.UTF_8));
+            }
+            builder.simpleAuth(authBuilder.build());
+        }
+
+        return builder.buildAsync();
+    }
+
+    public void connect(Mqtt5AsyncClient client) {
+        client.connectWith()
+                .cleanStart(configuration.isCleanStart())
+                .send()
+                .join();

Review Comment:
   Addressed. doStop() now uses the centralized stopClient() path instead of 
relying only on isConnected().
   
   The stop path marks the client for cancellation, and the 
disconnect/reconnect listeners ensure that an in-flight or scheduled 
auto-reconnect cannot leave the client connected after Camel has stopped.
   
   The same handling is applied to both HiveMQConsumer and HiveMQProducer.
   
   Addressed. The initial connect() wait is now bounded to 30 seconds using 
orTimeout(...). On timeout/failure, the client is stopped so the automatic 
reconnect process does not continue behind a failed Camel startup.
   
   Added HiveMQEndpointConnectTest covering the unreachable-broker case and 
stopping the client during an in-flight connection.
   
   Focused tests pass: 9/9, BUILD SUCCESS.



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