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-spring-boot.git
commit e28aed97ba502574e09d2d222128195b146580e4 Author: Zineb Bendhiba <bendhiba.zi...@gmail.com> AuthorDate: Wed Jun 17 20:54:12 2020 +0200 CAMEL-15193: camel-file-starter - Add back auto configuration for file cluster service --- .../src/main/docs/file-starter.adoc | 10 +- .../FileLockClusterServiceAutoConfiguration.java | 67 ++++++++++++ .../FileLockClusterServiceConfiguration.java | 115 +++++++++++++++++++++ .../src/main/resources/META-INF/spring.factories | 3 +- 4 files changed, 192 insertions(+), 3 deletions(-) diff --git a/components-starter/camel-file-starter/src/main/docs/file-starter.adoc b/components-starter/camel-file-starter/src/main/docs/file-starter.adoc index c7de0b3..a1042be 100644 --- a/components-starter/camel-file-starter/src/main/docs/file-starter.adoc +++ b/components-starter/camel-file-starter/src/main/docs/file-starter.adoc @@ -17,7 +17,7 @@ When using file with Spring Boot make sure to use the following Maven dependency ---- -The component supports 4 options, which are listed below. +The component supports 11 options, which are listed below. @@ -26,8 +26,14 @@ The component supports 4 options, which are listed below. | Name | Description | Default | Type | *camel.component.file.basic-property-binding* | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | Boolean | *camel.component.file.bridge-error-handler* | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean +| *camel.component.file.cluster.service.acquire-lock-delay* | The time to wait before starting to try to acquire lock. | | String +| *camel.component.file.cluster.service.acquire-lock-interval* | The time to wait between attempts to try to acquire lock. | | String +| *camel.component.file.cluster.service.attributes* | Custom service attributes. | | Map +| *camel.component.file.cluster.service.enabled* | Sets if the zookeeper cluster service should be enabled or not, default is false. | false | Boolean +| *camel.component.file.cluster.service.id* | Cluster Service ID | | String +| *camel.component.file.cluster.service.order* | Service lookup order/priority. | | Integer +| *camel.component.file.cluster.service.root* | The root path. | | String | *camel.component.file.enabled* | Whether to enable auto configuration of the file component. This is enabled by default. | | Boolean | *camel.component.file.lazy-start-producer* | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then [...] |=== - // spring-boot-auto-configure options: END diff --git a/components-starter/camel-file-starter/src/main/java/org/apache/camel/component/file/springboot/cluster/FileLockClusterServiceAutoConfiguration.java b/components-starter/camel-file-starter/src/main/java/org/apache/camel/component/file/springboot/cluster/FileLockClusterServiceAutoConfiguration.java new file mode 100644 index 0000000..63bd967 --- /dev/null +++ b/components-starter/camel-file-starter/src/main/java/org/apache/camel/component/file/springboot/cluster/FileLockClusterServiceAutoConfiguration.java @@ -0,0 +1,67 @@ +/** + * 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.file.springboot.cluster; + + +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.catalog.impl.TimePatternConverter; +import org.apache.camel.cluster.CamelClusterService; +import org.apache.camel.component.file.cluster.FileLockClusterService; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.cluster.ClusteredRouteControllerAutoConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +@Configuration +@AutoConfigureBefore({ ClusteredRouteControllerAutoConfiguration.class, CamelAutoConfiguration.class }) +@ConditionalOnProperty(prefix = "camel.component.file.cluster.service", name = "enabled") +@EnableConfigurationProperties(FileLockClusterServiceConfiguration.class) +public class FileLockClusterServiceAutoConfiguration { + @Autowired + private FileLockClusterServiceConfiguration configuration; + + @Bean(name = "file-lock-cluster-service") + @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) + public CamelClusterService consulClusterService() throws Exception { + FileLockClusterService service = new FileLockClusterService(); + + Optional.ofNullable(configuration.getId()) + .ifPresent(service::setId); + Optional.ofNullable(configuration.getRoot()) + .ifPresent(service::setRoot); + Optional.ofNullable(configuration.getOrder()) + .ifPresent(service::setOrder); + Optional.ofNullable(configuration.getAttributes()) + .ifPresent(service::setAttributes); + Optional.ofNullable(configuration.getAcquireLockDelay()) + .map(TimePatternConverter::toMilliSeconds) + .ifPresent(v -> service.setAcquireLockDelay(v, TimeUnit.MILLISECONDS)); + Optional.ofNullable(configuration.getAcquireLockInterval()) + .map(TimePatternConverter::toMilliSeconds) + .ifPresent(v -> service.setAcquireLockInterval(v, TimeUnit.MILLISECONDS)); + + return service; + } +} diff --git a/components-starter/camel-file-starter/src/main/java/org/apache/camel/component/file/springboot/cluster/FileLockClusterServiceConfiguration.java b/components-starter/camel-file-starter/src/main/java/org/apache/camel/component/file/springboot/cluster/FileLockClusterServiceConfiguration.java new file mode 100644 index 0000000..12f4752 --- /dev/null +++ b/components-starter/camel-file-starter/src/main/java/org/apache/camel/component/file/springboot/cluster/FileLockClusterServiceConfiguration.java @@ -0,0 +1,115 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.file.springboot.cluster; + +import java.util.Map; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.component.file.cluster.service") +public class FileLockClusterServiceConfiguration { + /** + * Sets if the zookeeper cluster service should be enabled or not, default is false. + */ + private boolean enabled; + + /** + * Cluster Service ID + */ + private String id; + + /** + * The root path. + */ + private String root; + + /** + * The time to wait before starting to try to acquire lock. + */ + private String acquireLockDelay; + + /** + * The time to wait between attempts to try to acquire lock. + */ + private String acquireLockInterval; + + /** + * Custom service attributes. + */ + private Map<String, Object> attributes; + + /** + * Service lookup order/priority. + */ + private Integer order; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getRoot() { + return root; + } + + public void setRoot(String root) { + this.root = root; + } + + public String getAcquireLockDelay() { + return acquireLockDelay; + } + + public void setAcquireLockDelay(String acquireLockDelay) { + this.acquireLockDelay = acquireLockDelay; + } + + public String getAcquireLockInterval() { + return acquireLockInterval; + } + + public void setAcquireLockInterval(String acquireLockInterval) { + this.acquireLockInterval = acquireLockInterval; + } + + public Map<String, Object> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, Object> attributes) { + this.attributes = attributes; + } + + public Integer getOrder() { + return order; + } + + public void setOrder(Integer order) { + this.order = order; + } +} diff --git a/components-starter/camel-file-starter/src/main/resources/META-INF/spring.factories b/components-starter/camel-file-starter/src/main/resources/META-INF/spring.factories index a6d6fa0..2706fd0 100644 --- a/components-starter/camel-file-starter/src/main/resources/META-INF/spring.factories +++ b/components-starter/camel-file-starter/src/main/resources/META-INF/spring.factories @@ -16,4 +16,5 @@ ## --------------------------------------------------------------------------- org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.apache.camel.component.file.springboot.FileComponentAutoConfiguration +org.apache.camel.component.file.springboot.FileComponentAutoConfiguration,\ +org.apache.camel.component.file.springboot.cluster.FileLockClusterServiceAutoConfiguration