This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ab0cf5ae5be11c0e031cb6489df5ca37c4aef02d
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Fri Apr 16 15:09:30 2021 +0200

    CAMEL-16512 - Camel-Azure components: mark the clients as autowired
---
 .../azure/eventhubs/EventHubsComponent.java        | 23 ----------------------
 .../azure/eventhubs/EventHubsConfiguration.java    | 16 ++-------------
 2 files changed, 2 insertions(+), 37 deletions(-)

diff --git 
a/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsComponent.java
 
b/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsComponent.java
index d87ce3a..01f08f2 100644
--- 
a/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsComponent.java
+++ 
b/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsComponent.java
@@ -53,11 +53,6 @@ public class EventHubsComponent extends DefaultComponent {
         final EventHubsEndpoint endpoint = new EventHubsEndpoint(uri, this, 
configuration);
         setProperties(endpoint, parameters);
 
-        if (configuration.isAutoDiscoverClient()) {
-            checkAndSetRegistryClient(configuration::setProducerAsyncClient, 
configuration::getProducerAsyncClient,
-                    EventHubProducerAsyncClient.class);
-        }
-
         // if we don't have client nor connectionString, we check for params
         if (areAzureClientsNotSet(configuration) && 
ObjectHelper.isEmpty(configuration.getConnectionString())) {
             checkAndSetNamespaceAndHubName(configuration, remaining);
@@ -78,24 +73,6 @@ public class EventHubsComponent extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    private <C> void checkAndSetRegistryClient(
-            final Consumer<C> setClientFn, final Supplier<C> getClientFn, 
final Class<C> clientType) {
-        if (ObjectHelper.isEmpty(getClientFn.get())) {
-            final Set<C> clients = 
getCamelContext().getRegistry().findByType(clientType);
-            if (clients.size() == 1) {
-                setClientFn.accept(clients.stream().findFirst().get());
-            } else if (clients.size() > 1) {
-                LOG.info(String.format("More than one %s instance in the 
registry, make sure to have only one instance",
-                        clientType.getSimpleName()));
-            } else {
-                LOG.info(String.format("No %s instance in the registry", 
clientType.getSimpleName()));
-            }
-        } else {
-            LOG.info(String.format("%s instance is already set at endpoint 
level: skipping the check in the registry",
-                    clientType.getSimpleName()));
-        }
-    }
-
     private void validateConfigurations(final EventHubsConfiguration 
configuration) {
         if (!isAccessKeyAndAccessNameSet(configuration)) {
             throw new IllegalArgumentException(
diff --git 
a/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsConfiguration.java
 
b/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsConfiguration.java
index 526c609..6a4b24f 100644
--- 
a/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsConfiguration.java
+++ 
b/components/camel-azure/camel-azure-eventhubs/src/main/java/org/apache/camel/component/azure/eventhubs/EventHubsConfiguration.java
@@ -28,6 +28,7 @@ import com.azure.messaging.eventhubs.EventProcessorClient;
 import com.azure.messaging.eventhubs.models.EventPosition;
 import com.azure.storage.common.StorageSharedKeyCredential;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
@@ -49,8 +50,6 @@ public class EventHubsConfiguration implements Cloneable {
     private AmqpTransportType amqpTransportType = AmqpTransportType.AMQP;
     @UriParam(label = "common")
     private AmqpRetryOptions amqpRetryOptions;
-    @UriParam(label = "common", defaultValue = "true")
-    private boolean autoDiscoverClient = true;
     @UriParam(label = "consumer", defaultValue = "$Default")
     private String consumerGroupName = "$Default";
     @UriParam(label = "consumer", defaultValue = "500")
@@ -68,6 +67,7 @@ public class EventHubsConfiguration implements Cloneable {
     @UriParam(label = "consumer")
     private Map<String, EventPosition> eventPosition = new HashMap<>();
     @UriParam(label = "producer")
+    @Metadata(autowired = true)
     private EventHubProducerAsyncClient producerAsyncClient;
     @UriParam(label = "producer")
     private String partitionKey;
@@ -196,18 +196,6 @@ public class EventHubsConfiguration implements Cloneable {
     }
 
     /**
-     * Setting the autoDiscoverClient mechanism, if true, the component will 
look for a client instance in the registry
-     * automatically otherwise it will skip that checking.
-     */
-    public boolean isAutoDiscoverClient() {
-        return autoDiscoverClient;
-    }
-
-    public void setAutoDiscoverClient(boolean autoDiscoverClient) {
-        this.autoDiscoverClient = autoDiscoverClient;
-    }
-
-    /**
      * Sets the identifier of the Event Hub partition that the {@link 
EventData events} will be sent to. If the
      * identifier is not specified, the Event Hubs service will be responsible 
for routing events that are sent to an
      * available partition.

Reply via email to