
io.camunda.zeebe.spring.client.config.ZeebeClientStarterAutoConfiguration Maven / Gradle / Ivy
package io.camunda.zeebe.spring.client.config;
import io.camunda.zeebe.client.ZeebeClientBuilder;
import io.camunda.zeebe.client.api.JsonMapper;
import io.camunda.zeebe.client.impl.ZeebeClientBuilderImpl;
import io.camunda.zeebe.client.impl.ZeebeObjectMapper;
import io.camunda.zeebe.spring.client.actuator.ZeebeActuatorConfiguration;
import io.camunda.zeebe.spring.client.annotation.customizer.ZeebeWorkerValueCustomizer;
import io.camunda.zeebe.spring.client.properties.PropertyBasedZeebeWorkerValueCustomizer;
import io.camunda.zeebe.spring.client.properties.ZeebeClientConfigurationProperties;
import io.grpc.ClientInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import java.util.List;
@Import(ZeebeActuatorConfiguration.class)
@EnableConfigurationProperties(ZeebeClientConfigurationProperties.class)
@Configuration
public class ZeebeClientStarterAutoConfiguration {
private final ZeebeClientConfigurationProperties configurationProperties;
public ZeebeClientStarterAutoConfiguration(ZeebeClientConfigurationProperties configurationProperties) {
this.configurationProperties = configurationProperties;
}
@Bean
@Primary
public ZeebeClientBuilder builder(JsonMapper jsonMapper,
@Autowired(required = false) List clientInterceptorList) {
final ZeebeClientBuilderImpl builder = new ZeebeClientBuilderImpl();
builder.gatewayAddress(configurationProperties.getGatewayAddress());
builder.defaultJobPollInterval(configurationProperties.getDefaultJobPollInterval());
builder.defaultJobTimeout(configurationProperties.getDefaultJobTimeout());
builder.defaultJobWorkerMaxJobsActive(configurationProperties.getDefaultJobWorkerMaxJobsActive());
builder.defaultJobWorkerName(configurationProperties.getDefaultJobWorkerName());
builder.defaultMessageTimeToLive(configurationProperties.getDefaultMessageTimeToLive());
builder.numJobWorkerExecutionThreads(configurationProperties.getNumJobWorkerExecutionThreads());
builder.defaultRequestTimeout(configurationProperties.getDefaultRequestTimeout());
builder.credentialsProvider(configurationProperties.getCredentialsProvider());
builder.caCertificatePath(configurationProperties.getCaCertificatePath());
if (configurationProperties.isPlaintextConnectionEnabled()) {
builder.usePlaintext();
}
builder.withJsonMapper(jsonMapper);
final List legacyInterceptors = configurationProperties.getInterceptors();
if (!legacyInterceptors.isEmpty()) {
builder.withInterceptors(legacyInterceptors.toArray(new ClientInterceptor[0]));
} else if (clientInterceptorList != null && !clientInterceptorList.isEmpty()) {
builder.withInterceptors(clientInterceptorList.toArray(new ClientInterceptor[0]));
}
return builder;
}
@Bean("propertyBasedZeebeWorkerValueCustomizer")
@ConditionalOnMissingBean(name = "propertyBasedZeebeWorkerValueCustomizer")
public ZeebeWorkerValueCustomizer propertyBasedZeebeWorkerValueCustomizer() {
return new PropertyBasedZeebeWorkerValueCustomizer(this.configurationProperties);
}
/**
* Registering a JsonMapper bean when there is none already exists in {@link org.springframework.beans.factory.BeanFactory}.
*
* NOTE: This method SHOULD NOT be explicitly called as it might lead to unexpected behaviour due to the
* {@link ConditionalOnMissingBean} annotation. i.e. Calling this method when another JsonMapper bean is defined in the context
* might throw {@link org.springframework.beans.factory.NoSuchBeanDefinitionException}
*
* @return a new JsonMapper bean if none already exists in {@link org.springframework.beans.factory.BeanFactory}
*/
@Bean(name = "zeebeJsonMapper")
@ConditionalOnMissingBean
public JsonMapper jsonMapper() {
return new ZeebeObjectMapper();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy