Skip to content

Commit

Permalink
Fix new spring coroutines api
Browse files Browse the repository at this point in the history
  • Loading branch information
Артемьев Вячеслав authored and Артемьев Вячеслав committed Sep 17, 2019
1 parent d30ddc2 commit c5b5797
Showing 1 changed file with 12 additions and 6 deletions.
Expand Up @@ -16,7 +16,6 @@ import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.web.reactive.function.server.awaitBody
import org.springframework.web.reactive.function.server.bodyAndAwait
import org.springframework.web.reactive.function.server.coRouter

@SpringBootApplication
Expand Down Expand Up @@ -44,24 +43,31 @@ class Handlers(private val connection: Connection) {
var message = "default_value"
connection.channel {
consume("test_queue", 1) {
consumeMessageWithConfirm({
consumeMessageWithConfirm {
println("Got a message!")
message = String(it.body)
})
}
}
}
return ServerResponse.ok().bodyAndAwait(Message(message))
return ServerResponse.ok().bodyValue(Message(message)).awaitSingle()
}

suspend fun push(request: ServerRequest): ServerResponse {
val message = request.awaitBody<Message>() ?: throw RuntimeException("A message can't be empty")
var ack = false
connection.confirmChannel {
publish {
ack = publishWithConfirm(OutboundMessage("", "test_queue", MessageProperties.PERSISTENT_BASIC, message.message))
ack = publishWithConfirm(
OutboundMessage(
"",
"test_queue",
MessageProperties.PERSISTENT_BASIC,
message.message
)
)
}
}
return if (ack) ServerResponse.ok().bodyAndAwait("Done") else ServerResponse.status(500).build().awaitSingle()
return if (ack) ServerResponse.ok().bodyValue("Done").awaitSingle() else ServerResponse.status(500).build().awaitSingle()
}
}

Expand Down

0 comments on commit c5b5797

Please sign in to comment.