|
| 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 | +} |
0 commit comments