jamesnetherton commented on a change in pull request #4723:
URL: https://github.com/apache/camel/pull/4723#discussion_r536161246



##########
File path: 
components/camel-vertx-kafka/camel-vertx-kafka-component/src/main/java/org/apache/camel/component/vertx/kafka/VertxKafkaComponent.java
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.vertx.kafka;
+
+import java.util.Map;
+
+import io.vertx.core.Vertx;
+import io.vertx.core.VertxOptions;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import 
org.apache.camel.component.vertx.kafka.configuration.VertxKafkaConfiguration;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.PropertiesHelper;
+
+@Component("vertx-kafka")
+public class VertxKafkaComponent extends DefaultComponent {
+
+    @Metadata
+    private VertxKafkaConfiguration configuration = new 
VertxKafkaConfiguration();
+
+    @Metadata(label = "advanced", autowired = true)
+    private Vertx vertx;
+    @Metadata(label = "advanced")
+    private VertxOptions vertxOptions;
+
+    public VertxKafkaComponent() {
+    }
+
+    public VertxKafkaComponent(CamelContext context) {
+        super(context);
+    }
+
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+
+        if (ObjectHelper.isEmpty(remaining)) {
+            throw new IllegalArgumentException("Topic must be configured on 
endpoint using syntax kafka:topic");
+        }
+
+        final VertxKafkaConfiguration configuration
+                = this.configuration != null ? this.configuration.copy() : new 
VertxKafkaConfiguration();
+
+        configuration.setTopic(remaining);
+
+        final VertxKafkaEndpoint endpoint = new VertxKafkaEndpoint(uri, this, 
configuration);
+
+        // extract the additional properties map
+        if (PropertiesHelper.hasProperties(parameters, 
"additionalProperties.")) {
+            final Map<String, Object> additionalProperties = 
endpoint.getConfiguration().getAdditionalProperties();
+
+            // add and overwrite additional properties from endpoint to
+            // pre-configured properties
+            
additionalProperties.putAll(PropertiesHelper.extractProperties(parameters, 
"additionalProperties."));
+        }
+
+        setProperties(endpoint, parameters);
+
+        validateConfigurations(configuration);
+
+        return endpoint;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        if (vertx == null) {
+            if (vertxOptions != null) {
+                vertx = Vertx.vertx(vertxOptions);
+            } else {
+                vertx = Vertx.vertx();
+            }
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (vertx != null) {
+            vertx.close();
+        }
+        vertx = null;

Review comment:
       Might be better to do like 
[`VertxComponent.doStop()`](https://github.com/apache/camel/blob/master/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxComponent.java#L201-L209)
 and handle the case where the Vert.x instance was provided by the user. In 
that scenario you probably don't want to clean it up as there may be other 
things that depend on it.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to