Skip to content

Expose Spring Integration global properties #25377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@
TaskSchedulingAutoConfiguration.class })
public class IntegrationAutoConfiguration {

@Bean(name = IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME)
@ConditionalOnMissingBean(name = IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME)
public static org.springframework.integration.context.IntegrationProperties integrationGlobalProperties(
IntegrationProperties properties) {
org.springframework.integration.context.IntegrationProperties integrationProperties = new org.springframework.integration.context.IntegrationProperties();
integrationProperties.setChannelsAutoCreate(properties.getChannels().isAutoCreate());
integrationProperties.setChannelsMaxUnicastSubscribers(properties.getChannels().getMaxUnicastSubscribers());
integrationProperties.setChannelsMaxBroadcastSubscribers(properties.getChannels().getMaxBroadcastSubscribers());
integrationProperties.setErrorChannelRequireSubscribers(properties.getChannels().isErrorRequireSubscribers());
integrationProperties.setErrorChannelIgnoreFailures(properties.getChannels().isErrorIgnoreFailures());
integrationProperties
.setMessagingTemplateThrowExceptionOnLateReply(properties.getEndpoints().isThrowExceptionOnLateReply());
integrationProperties.setReadOnlyHeaders(properties.getEndpoints().getReadOnlyHeaders());
integrationProperties.setNoAutoStartupEndpoints(properties.getEndpoints().getNoAutoStartup());
return integrationProperties;
}

/**
* Basic Spring Integration configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright 2012-2021 the original author or authors.
*
* 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
*
* https://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.springframework.boot.autoconfigure.integration;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.boot.env.PropertiesPropertySourceLoader;
import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginLookup;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.integration.context.IntegrationProperties;

/**
* The {@link EnvironmentPostProcessor} for Spring Integration.
*
* @author Artem Bilan
* @since 2.5
*/
public class IntegrationEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {

@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
registerIntegrationPropertiesFileSource(environment);
}

private static void registerIntegrationPropertiesFileSource(ConfigurableEnvironment environment) {
Resource integrationPropertiesResource = new ClassPathResource("META-INF/spring.integration.properties");
PropertiesPropertySourceLoader loader = new PropertiesPropertySourceLoader();
try {
OriginTrackedMapPropertySource propertyFileSource = (OriginTrackedMapPropertySource) loader
.load("integration-properties-file", integrationPropertiesResource).get(0);

environment.getPropertySources().addLast(new IntegrationPropertySource(propertyFileSource));
}
catch (FileNotFoundException ex) {
// Ignore when no META-INF/spring.integration.properties file in classpath
}
catch (IOException ex) {
throw new IllegalStateException(
"Failed to load integration properties from " + integrationPropertiesResource, ex);
}
}

private static final class IntegrationPropertySource extends PropertySource<Map<String, Object>>
implements OriginLookup<String> {

private static final String PREFIX = "spring.integration.";

private static final Map<String, String> KEYS_MAPPING = new HashMap<>();

static {
KEYS_MAPPING.put(PREFIX + "channels.auto-create", IntegrationProperties.CHANNELS_AUTOCREATE);
KEYS_MAPPING.put(PREFIX + "channels.max-unicast-subscribers",
IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS);
KEYS_MAPPING.put(PREFIX + "channels.max-broadcast-subscribers",
IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS);
KEYS_MAPPING.put(PREFIX + "channels.error-require-subscribers",
IntegrationProperties.ERROR_CHANNEL_REQUIRE_SUBSCRIBERS);
KEYS_MAPPING.put(PREFIX + "channels.error-ignore-failures",
IntegrationProperties.ERROR_CHANNEL_IGNORE_FAILURES);
KEYS_MAPPING.put(PREFIX + "endpoints.throw-exception-on-late-reply",
IntegrationProperties.THROW_EXCEPTION_ON_LATE_REPLY);
KEYS_MAPPING.put(PREFIX + "endpoints.read-only-headers", IntegrationProperties.READ_ONLY_HEADERS);
KEYS_MAPPING.put(PREFIX + "endpoints.no-auto-startup", IntegrationProperties.ENDPOINTS_NO_AUTO_STARTUP);
}

private final OriginTrackedMapPropertySource origin;

IntegrationPropertySource(OriginTrackedMapPropertySource origin) {
super("original-integration-properties", origin.getSource());
this.origin = origin;
}

@Override
public Object getProperty(String name) {
return this.origin.getProperty(KEYS_MAPPING.get(name));
}

@Override
public Origin getOrigin(String key) {
return this.origin.getOrigin(KEYS_MAPPING.get(name));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@
@ConfigurationProperties(prefix = "spring.integration")
public class IntegrationProperties {

private final Channels channels = new Channels();

private final Endpoints endpoints = new Endpoints();

private final Jdbc jdbc = new Jdbc();

private final RSocket rsocket = new RSocket();

public Channels getChannels() {
return this.channels;
}

public Endpoints getEndpoints() {
return this.endpoints;
}

public Jdbc getJdbc() {
return this.jdbc;
}
Expand All @@ -44,6 +56,118 @@ public RSocket getRsocket() {
return this.rsocket;
}

public static class Channels {

/**
* Whether to create input channels when no respective beans.
*/
private boolean autoCreate = true;

/**
* Default number of max subscribers on unicasting channels.
*/
private int maxUnicastSubscribers = Integer.MAX_VALUE;

/**
* Default number of max subscribers on broadcasting channels.
*/
private int maxBroadcastSubscribers = Integer.MAX_VALUE;

/**
* Require subscribers flag for global 'errorChannel'.
*/
private boolean errorRequireSubscribers = true;

/**
* Ignore failures flag for global 'errorChannel'.
*/
private boolean errorIgnoreFailures = true;

public void setAutoCreate(boolean autoCreate) {
this.autoCreate = autoCreate;
}

public boolean isAutoCreate() {
return this.autoCreate;
}

public void setMaxUnicastSubscribers(int maxUnicastSubscribers) {
this.maxUnicastSubscribers = maxUnicastSubscribers;
}

public int getMaxUnicastSubscribers() {
return this.maxUnicastSubscribers;
}

public void setMaxBroadcastSubscribers(int maxBroadcastSubscribers) {
this.maxBroadcastSubscribers = maxBroadcastSubscribers;
}

public int getMaxBroadcastSubscribers() {
return this.maxBroadcastSubscribers;
}

public void setErrorRequireSubscribers(boolean errorRequireSubscribers) {
this.errorRequireSubscribers = errorRequireSubscribers;
}

public boolean isErrorRequireSubscribers() {
return this.errorRequireSubscribers;
}

public void setErrorIgnoreFailures(boolean errorIgnoreFailures) {
this.errorIgnoreFailures = errorIgnoreFailures;
}

public boolean isErrorIgnoreFailures() {
return this.errorIgnoreFailures;
}

}

public static class Endpoints {

/**
* Whether throw an exception on late reply for gateways.
*/
private boolean throwExceptionOnLateReply = false;

/**
* Ignored headers during message building.
*/
private String[] readOnlyHeaders = {};

/**
* Spring Integration endpoints do not start automatically.
*/
private String[] noAutoStartup = {};

public void setThrowExceptionOnLateReply(boolean throwExceptionOnLateReply) {
this.throwExceptionOnLateReply = throwExceptionOnLateReply;
}

public boolean isThrowExceptionOnLateReply() {
return this.throwExceptionOnLateReply;
}

public void setReadOnlyHeaders(String[] readOnlyHeaders) {
this.readOnlyHeaders = readOnlyHeaders;
}

public String[] getReadOnlyHeaders() {
return this.readOnlyHeaders;
}

public void setNoAutoStartup(String[] noAutoStartup) {
this.noAutoStartup = noAutoStartup;
}

public String[] getNoAutoStartup() {
return this.noAutoStartup;
}

}

public static class Jdbc {

private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/"
Expand Down Expand Up @@ -139,7 +263,7 @@ public static class Server {
/**
* Whether to handle message mapping for RSocket via Spring Integration.
*/
boolean messageMappingEnabled;
private boolean messageMappingEnabled;

public boolean isMessageMappingEnabled() {
return this.messageMappingEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingL
org.springframework.context.ApplicationListener=\
org.springframework.boot.autoconfigure.BackgroundPreinitializer

# Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.autoconfigure.integration.IntegrationEnvironmentPostProcessor

# Auto Configuration Import Listeners
org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\
org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener
Expand Down
Loading