io.camunda.zeebe.spring.client.configuration.ZeebeClientAllAutoConfiguration Maven / Gradle / Ivy
/*
* Copyright © 2017 camunda services GmbH ([email protected])
*
* Licensed 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 io.camunda.zeebe.spring.client.configuration;
import io.camunda.zeebe.client.api.JsonMapper;
import io.camunda.zeebe.client.api.worker.BackoffSupplier;
import io.camunda.zeebe.client.impl.worker.ExponentialBackoffBuilderImpl;
import io.camunda.zeebe.spring.client.annotation.customizer.ZeebeWorkerValueCustomizer;
import io.camunda.zeebe.spring.client.jobhandling.CommandExceptionHandlingStrategy;
import io.camunda.zeebe.spring.client.jobhandling.DefaultCommandExceptionHandlingStrategy;
import io.camunda.zeebe.spring.client.jobhandling.JobWorkerManager;
import io.camunda.zeebe.spring.client.jobhandling.ZeebeClientExecutorService;
import io.camunda.zeebe.spring.client.metrics.MetricsRecorder;
import io.camunda.zeebe.spring.client.properties.CommonConfigurationProperties;
import io.camunda.zeebe.spring.client.properties.PropertyBasedZeebeWorkerValueCustomizer;
import io.camunda.zeebe.spring.client.properties.ZeebeClientConfigurationProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
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.Import;
@ConditionalOnProperty(
prefix = "zeebe.client",
name = "enabled",
havingValue = "true",
matchIfMissing = true)
@Import(AnnotationProcessorConfiguration.class)
@EnableConfigurationProperties({
ZeebeClientConfigurationProperties.class,
CommonConfigurationProperties.class
})
public class ZeebeClientAllAutoConfiguration {
private final ZeebeClientConfigurationProperties configurationProperties;
public ZeebeClientAllAutoConfiguration(
final ZeebeClientConfigurationProperties configurationProperties) {
this.configurationProperties = configurationProperties;
}
@Bean
@ConditionalOnMissingBean
public ZeebeClientExecutorService zeebeClientExecutorService() {
return ZeebeClientExecutorService.createDefault(
configurationProperties.getNumJobWorkerExecutionThreads());
}
@Bean
@ConditionalOnMissingBean
public CommandExceptionHandlingStrategy commandExceptionHandlingStrategy(
final ZeebeClientExecutorService scheduledExecutorService) {
return new DefaultCommandExceptionHandlingStrategy(
backoffSupplier(), scheduledExecutorService.get());
}
@Bean
public JobWorkerManager jobWorkerManager(
final CommandExceptionHandlingStrategy commandExceptionHandlingStrategy,
final JsonMapper jsonMapper,
final MetricsRecorder metricsRecorder) {
return new JobWorkerManager(commandExceptionHandlingStrategy, jsonMapper, metricsRecorder);
}
@Bean
public BackoffSupplier backoffSupplier() {
return new ExponentialBackoffBuilderImpl()
.maxDelay(1000L)
.minDelay(50L)
.backoffFactor(1.5)
.jitterFactor(0.2)
.build();
}
@Bean("propertyBasedZeebeWorkerValueCustomizer")
@ConditionalOnMissingBean(name = "propertyBasedZeebeWorkerValueCustomizer")
public ZeebeWorkerValueCustomizer propertyBasedZeebeWorkerValueCustomizer() {
return new PropertyBasedZeebeWorkerValueCustomizer(configurationProperties);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy