Skip to content

Commit f95c103

Browse files
committed
Split RSocket configuration from RSocketStrategiesCustomizer
1 parent eccafd3 commit f95c103

File tree

3 files changed

+53
-19
lines changed

3 files changed

+53
-19
lines changed

spring-cloud-function-rsocket/src/main/java/org/springframework/cloud/function/rsocket/RSocketAutoConfiguration.java

+1-19
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2222
import org.springframework.boot.autoconfigure.rsocket.RSocketMessageHandlerCustomizer;
2323
import org.springframework.boot.context.properties.EnableConfigurationProperties;
24-
import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer;
2524
import org.springframework.cloud.function.context.FunctionCatalog;
2625
import org.springframework.cloud.function.context.FunctionProperties;
2726
import org.springframework.cloud.function.json.JsonMapper;
2827
import org.springframework.context.annotation.Bean;
2928
import org.springframework.context.annotation.Configuration;
3029
import org.springframework.context.annotation.Primary;
3130
import org.springframework.messaging.rsocket.RSocketStrategies;
32-
import org.springframework.messaging.rsocket.RSocketStrategies.Builder;
3331

3432
/**
3533
* Main configuration class for components required to support RSocket integration with
@@ -41,26 +39,10 @@
4139
* @since 3.1
4240
*/
4341
@Configuration(proxyBeanMethods = false)
44-
@EnableConfigurationProperties({ FunctionProperties.class, RSocketFunctionProperties.class })
42+
@EnableConfigurationProperties(FunctionProperties.class)
4543
@ConditionalOnProperty(name = FunctionProperties.PREFIX + ".rsocket.enabled", matchIfMissing = true)
4644
class RSocketAutoConfiguration {
4745

48-
@Bean
49-
RSocketStrategiesCustomizer rSocketStrategiesCustomizer(JsonMapper jsonMapper) {
50-
return new RSocketStrategiesCustomizer() {
51-
@Override
52-
public void customize(Builder strategies) {
53-
strategies
54-
.encoders(encoders -> {
55-
encoders.add(0, new MessageAwareJsonEncoder(jsonMapper, true));
56-
})
57-
.decoders(decoders -> {
58-
decoders.add(0, new MessageAwareJsonDecoder(jsonMapper));
59-
});
60-
}
61-
};
62-
}
63-
6446
@Bean
6547
@ConditionalOnMissingBean
6648
@Primary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2021-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.function.rsocket;
18+
19+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
20+
import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer;
21+
import org.springframework.cloud.function.context.FunctionProperties;
22+
import org.springframework.cloud.function.json.JsonMapper;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.messaging.rsocket.RSocketStrategies.Builder;
26+
27+
/**
28+
* @author Oleg Zhurakousky
29+
*
30+
* @since 3.2
31+
*/
32+
@Configuration(proxyBeanMethods = false)
33+
@EnableConfigurationProperties({ FunctionProperties.class, RSocketFunctionProperties.class })
34+
public class RSocketCustomizerConfiguration {
35+
36+
@Bean
37+
RSocketStrategiesCustomizer rSocketStrategiesCustomizer(JsonMapper jsonMapper) {
38+
return new RSocketStrategiesCustomizer() {
39+
@Override
40+
public void customize(Builder strategies) {
41+
strategies
42+
.encoders(encoders -> {
43+
encoders.add(0, new MessageAwareJsonEncoder(jsonMapper, true));
44+
})
45+
.decoders(decoders -> {
46+
decoders.add(0, new MessageAwareJsonDecoder(jsonMapper));
47+
});
48+
}
49+
};
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
22
org.springframework.cloud.function.rsocket.RSocketAutoConfiguration,\
3+
org.springframework.cloud.function.rsocket.RSocketCustomizerConfiguration,\
34
org.springframework.cloud.function.rsocket.RSocketRoutingAutoConfiguration

0 commit comments

Comments
 (0)