In a `coRouter` context I'd like to use a `TEXT_EV...
# spring
j
In a
coRouter
context I'd like to use a
TEXT_EVENT_STREAM
like this:
Copy code
val flux: Flux<String> = loggingThing()
return ok()
            .contentType(MediaType.TEXT_EVENT_STREAM)
            .body(result, String::class.java)
but coRouter expects a
ServerResponse
and not a
Mono<ServerResponse>
.
bodyAndAwait
wouldn't work with
Please specify the element class by using body(Publisher, Class)
. Is such a thing supported out of the box with coRouter DSL or should I return to a standard router here? Using Spring Boot 2.1.6 (and coRouter implementation from 2.2.0-M6 I think)
d
The coRouter DSl is for Kotlins Coroutine usage. In my eyes it is nice to have an `ServerResponse`directly as return type instead of the Mono wrapper. But you can use the
router
DSL instead and get the Mono you`ll need.
s
First please use Boot 2.2 snapshots and avoid mixing Boot 2.1 with coRouter 2.2.
These API have moved so I am refering to snapshots to be sure we talk about the same thing.
So with snapshot you should use
bodyAndAwait
for that use case.
Or
bodyValueAndAwait
if you are using plain values.
j
bodyAndAwait indeed works as expected in 2.2 SNAPSHOT and standard router DSL + Mono<ServerResponse> for 2.1.6 Thanks!
👍 1