Skip to content

Commit 251fcb2

Browse files
refactor(spring): drop ChannelSendOperator from the DataSource return-value handler (#30)
Sets the DataSource response flow directly in DataSourcePayloadReturnValueHandler instead of routing it through a WebFlux ChannelSendOperator. The operator was an HTTP-response idiom that only pulled spring-web into the messaging starter for no benefit — the flow is cold and collected later, so a synchronous set plus Mono.empty() is equivalent.
1 parent fe97d94 commit 251fcb2

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

spring/src/main/kotlin/com/caplin/integration/datasourcex/spring/internal/DataSourcePayloadReturnValueHandler.kt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import org.reactivestreams.Publisher
88
import org.springframework.core.MethodParameter
99
import org.springframework.core.ReactiveAdapterRegistry
1010
import org.springframework.core.ResolvableType
11-
import org.springframework.http.server.reactive.ChannelSendOperator
12-
import org.springframework.lang.Nullable
1311
import org.springframework.messaging.Message
1412
import org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler
1513
import org.springframework.util.Assert
@@ -32,26 +30,18 @@ internal class DataSourcePayloadReturnValueHandler(
3230
returnType: MethodParameter,
3331
message: Message<*>,
3432
): Mono<Void> {
35-
if (returnValue == null) {
36-
val responseRef = getResponseReference(message)
37-
responseRef?.set(emptyFlow())
38-
}
39-
40-
val content = getContent(returnValue, returnType)
41-
return ChannelSendOperator(content) { publisher -> handleContent(publisher.asFlow(), message) }
33+
val responseRef = getResponseReference(message)
34+
checkNotNull(responseRef) { "Missing '$RESPONSE_HEADER'" }
35+
responseRef.set(
36+
if (returnValue == null) emptyFlow() else getContent(returnValue, returnType).asFlow()
37+
)
38+
return Mono.empty()
4239
}
4340

44-
private fun getContent(@Nullable content: Any?, returnType: MethodParameter): Publisher<Any> {
41+
private fun getContent(content: Any, returnType: MethodParameter): Publisher<Any> {
4542
val returnValueType = ResolvableType.forMethodParameter(returnType)
4643
val adapter = reactiveAdapterRegistry.getAdapter(returnValueType.resolve(), content)
47-
return adapter?.run { toPublisher(content) } ?: Mono.justOrEmpty(content)
48-
}
49-
50-
private fun handleContent(encodedContent: Flow<Any>, message: Message<*>): Mono<Void?> {
51-
val responseRef: AtomicReference<Flow<Any>>? = getResponseReference(message)
52-
checkNotNull(responseRef) { "Missing '$RESPONSE_HEADER'" }
53-
responseRef.set(encodedContent)
54-
return Mono.empty()
44+
return adapter?.run { toPublisher(content) } ?: Mono.just(content)
5545
}
5646

5747
@Suppress("UNCHECKED_CAST")

0 commit comments

Comments
 (0)