committed by
GitHub
parent
b5ed0bdf1e
commit
c64b259d91
@@ -49,6 +49,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Corneil du Plessis
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(AggregatorFunctionProperties.class)
|
||||
@@ -61,11 +62,12 @@ public class AggregatorFunctionConfiguration {
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
@Bean
|
||||
public Function<Flux<Message<?>>, Flux<Message<?>>> aggregatorFunction(FluxMessageChannel inputChannel,
|
||||
FluxMessageChannel outputChannel) {
|
||||
|
||||
public Function<Flux<Message<?>>, Flux<Message<?>>> aggregatorFunction(
|
||||
FluxMessageChannel inputChannel,
|
||||
FluxMessageChannel outputChannel
|
||||
) {
|
||||
return input -> Flux.from(outputChannel)
|
||||
.doOnRequest((request) -> inputChannel.subscribeTo(input));
|
||||
.doOnRequest((request) -> inputChannel.subscribeTo(input));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -81,12 +83,12 @@ public class AggregatorFunctionConfiguration {
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "inputChannel")
|
||||
public AggregatorFactoryBean aggregator(
|
||||
@Nullable CorrelationStrategy correlationStrategy,
|
||||
@Nullable ReleaseStrategy releaseStrategy,
|
||||
@Nullable MessageGroupProcessor messageGroupProcessor,
|
||||
@Nullable MessageGroupStore messageStore,
|
||||
@Qualifier("outputChannel") MessageChannel outputChannel,
|
||||
@Nullable ComponentCustomizer<AggregatorFactoryBean> aggregatorCustomizer) {
|
||||
@Nullable CorrelationStrategy correlationStrategy,
|
||||
@Nullable ReleaseStrategy releaseStrategy,
|
||||
@Nullable MessageGroupProcessor messageGroupProcessor,
|
||||
@Nullable MessageGroupStore messageStore,
|
||||
@Qualifier("outputChannel") MessageChannel outputChannel,
|
||||
@Nullable ComponentCustomizer<AggregatorFactoryBean> aggregatorCustomizer) {
|
||||
|
||||
AggregatorFactoryBean aggregator = new AggregatorFactoryBean();
|
||||
aggregator.setExpireGroupsUponCompletion(true);
|
||||
@@ -144,8 +146,11 @@ public class AggregatorFunctionConfiguration {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(MessageGroupStore.class)
|
||||
@Import({ MessageStoreConfiguration.Mongo.class, MessageStoreConfiguration.Redis.class,
|
||||
MessageStoreConfiguration.Gemfire.class, MessageStoreConfiguration.Jdbc.class })
|
||||
@Import({
|
||||
MessageStoreConfiguration.Mongo.class,
|
||||
MessageStoreConfiguration.Redis.class,
|
||||
MessageStoreConfiguration.Jdbc.class
|
||||
})
|
||||
protected static class MessageStoreAutoConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@@ -30,14 +30,13 @@ import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.geode.boot.autoconfigure.ClientCacheAutoConfiguration;
|
||||
import org.springframework.geode.boot.autoconfigure.SslAutoConfiguration;
|
||||
|
||||
/**
|
||||
* An {@link EnvironmentPostProcessor} to add {@code spring.autoconfigure.exclude} property
|
||||
* since we can't use {@code application.properties} from the library perspective.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Corneil du Plessis
|
||||
*/
|
||||
public class ExcludeStoresAutoConfigurationEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
@@ -52,18 +51,10 @@ public class ExcludeStoresAutoConfigurationEnvironmentPostProcessor implements E
|
||||
MongoAutoConfiguration.class.getName() + ", " +
|
||||
MongoDataAutoConfiguration.class.getName() + ", " +
|
||||
MongoRepositoriesAutoConfiguration.class.getName() + ", " +
|
||||
ClientCacheAutoConfiguration.class.getName() + ", " +
|
||||
RedisAutoConfiguration.class.getName() + ", " +
|
||||
RedisRepositoriesAutoConfiguration.class.getName());
|
||||
|
||||
String messageStoreType = environment.getProperty(AggregatorFunctionProperties.PREFIX + ".message-store-type");
|
||||
if (!AggregatorFunctionProperties.MessageStoreType.GEMFIRE.equals(messageStoreType)) {
|
||||
properties.setProperty(SslAutoConfiguration.SECURITY_SSL_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY,
|
||||
"false");
|
||||
}
|
||||
|
||||
propertySources.addLast(
|
||||
new PropertiesPropertySource("aggregator.exclude.stores.auto-configuration", properties));
|
||||
propertySources.addLast(new PropertiesPropertySource("aggregator.exclude.stores.auto-configuration", properties));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,7 @@ package org.springframework.cloud.fn.aggregator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Region;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
@@ -32,13 +28,9 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.config.annotation.EnablePdx;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.geode.boot.autoconfigure.ClientCacheAutoConfiguration;
|
||||
import org.springframework.integration.gemfire.store.GemfireMessageStore;
|
||||
import org.springframework.integration.jdbc.store.JdbcMessageStore;
|
||||
import org.springframework.integration.mongodb.store.ConfigurableMongoDbMessageStore;
|
||||
import org.springframework.integration.mongodb.support.BinaryToMessageConverter;
|
||||
@@ -55,6 +47,7 @@ import org.springframework.util.StringUtils;
|
||||
* via matched configuration properties.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Corneil du Plessis
|
||||
*/
|
||||
class MessageStoreConfiguration {
|
||||
|
||||
@@ -99,30 +92,6 @@ class MessageStoreConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnClass(GemfireMessageStore.class)
|
||||
@ConditionalOnProperty(prefix = AggregatorFunctionProperties.PREFIX,
|
||||
name = "message-store-type",
|
||||
havingValue = AggregatorFunctionProperties.MessageStoreType.GEMFIRE)
|
||||
@Import(ClientCacheAutoConfiguration.class)
|
||||
@EnablePdx
|
||||
static class Gemfire {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ClientRegionFactoryBean<?, ?> gemfireRegion(GemFireCache cache, AggregatorFunctionProperties properties) {
|
||||
ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = new ClientRegionFactoryBean<>();
|
||||
clientRegionFactoryBean.setCache(cache);
|
||||
clientRegionFactoryBean.setName(properties.getMessageStoreEntity());
|
||||
return clientRegionFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageGroupStore messageStore(Region<Object, Object> region) {
|
||||
return new GemfireMessageStore(region);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnClass(JdbcMessageStore.class)
|
||||
@ConditionalOnProperty(prefix = AggregatorFunctionProperties.PREFIX,
|
||||
name = "message-store-type",
|
||||
|
||||
@@ -21,10 +21,8 @@ import java.util.function.Function;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.geode.boot.autoconfigure.SslAutoConfiguration;
|
||||
import org.springframework.integration.aggregator.AggregatingMessageHandler;
|
||||
import org.springframework.integration.store.MessageGroupStore;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -32,6 +30,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Corneil du Plessis
|
||||
*/
|
||||
@SpringBootTest
|
||||
@DirtiesContext
|
||||
@@ -46,9 +45,6 @@ public abstract class AbstractAggregatorFunctionTests {
|
||||
@Autowired
|
||||
protected AggregatingMessageHandler aggregatingMessageHandler;
|
||||
|
||||
@Value("${" + SslAutoConfiguration.SECURITY_SSL_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY + ":true}")
|
||||
protected Boolean geodeSslEnable;
|
||||
|
||||
@SpringBootApplication
|
||||
static class AggregatorFunctionTestApplication {
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Corneil du Plessis
|
||||
*/
|
||||
public class DefaultAggregatorTests extends AbstractAggregatorFunctionTests {
|
||||
|
||||
@@ -65,8 +66,6 @@ public class DefaultAggregatorTests extends AbstractAggregatorFunctionTests {
|
||||
assertThat(this.messageGroupStore).isNull();
|
||||
assertThat(this.aggregatingMessageHandler.getMessageStore()).isInstanceOf(SimpleMessageStore.class);
|
||||
|
||||
// Also verify geode ssl flag not enabled for default message store (non-geode)
|
||||
assertThat(this.geodeSslEnable).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020-2022 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.cloud.fn.aggregator;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.gemfire.store.GemfireMessageStore;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@TestPropertySource(properties = {
|
||||
"aggregator.message-store-type=gemfire",
|
||||
"aggregator.groupTimeout=10" })
|
||||
public class GroupTimeOutAndGemfireMessageStoreAggregatorTests extends AbstractAggregatorFunctionTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Flux<Message<?>> input =
|
||||
Flux.just(MessageBuilder.withPayload("1")
|
||||
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "my_correlation")
|
||||
.build());
|
||||
|
||||
Flux<Message<?>> output = this.aggregatorFunction.apply(input);
|
||||
|
||||
output.as(StepVerifier::create)
|
||||
.assertNext((message) ->
|
||||
assertThat(message)
|
||||
.extracting(Message::getPayload)
|
||||
.isInstanceOf(List.class)
|
||||
.asList()
|
||||
.hasSize(1)
|
||||
.contains("1"))
|
||||
.thenCancel()
|
||||
.verify(Duration.ofSeconds(10));
|
||||
|
||||
assertThat(this.messageGroupStore).isInstanceOf(GemfireMessageStore.class);
|
||||
assertThat(this.aggregatingMessageHandler.getMessageStore()).isSameAs(this.messageGroupStore);
|
||||
|
||||
// Also verify geode ssl flag enabled for geode message stores
|
||||
assertThat(this.geodeSslEnable).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Corneil du Plessis
|
||||
*/
|
||||
@TestPropertySource(properties = "aggregator.message-store-type=jdbc")
|
||||
public class JdbcMessageStoreAggregatorTests extends AbstractAggregatorFunctionTests {
|
||||
@@ -67,9 +68,6 @@ public class JdbcMessageStoreAggregatorTests extends AbstractAggregatorFunctionT
|
||||
assertThat(this.messageGroupStore).isInstanceOf(JdbcMessageStore.class);
|
||||
|
||||
assertThat(this.aggregatingMessageHandler.getMessageStore()).isSameAs(this.messageGroupStore);
|
||||
|
||||
// Also verify geode ssl flag not enabled for non-geode message stores
|
||||
assertThat(this.geodeSslEnable).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user