From 7a87fdd2cc5f393eb65232f10b505c374e478662 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Fri, 25 Mar 2022 16:01:50 +0700 Subject: [PATCH] Udated stream api --- .../cubetiqs/live/service/LiveServiceApplication.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/cubetiqs/live/service/LiveServiceApplication.kt b/src/main/kotlin/com/cubetiqs/live/service/LiveServiceApplication.kt index 505e97c..fd2f8ef 100644 --- a/src/main/kotlin/com/cubetiqs/live/service/LiveServiceApplication.kt +++ b/src/main/kotlin/com/cubetiqs/live/service/LiveServiceApplication.kt @@ -5,15 +5,15 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.context.ApplicationEventPublisher -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController +import org.springframework.scheduling.annotation.Async +import org.springframework.scheduling.annotation.EnableAsync +import org.springframework.web.bind.annotation.* import reactor.core.publisher.Flux import reactor.core.publisher.Flux.generate import java.util.concurrent.ThreadLocalRandom @SpringBootApplication +@EnableAsync class LiveServiceApplication fun main(args: Array) { @@ -33,6 +33,7 @@ class HelloController( events = Flux.create(eventPublisher).share() } + @Async @RequestMapping("/publish") fun publish(@RequestParam(value = "message", defaultValue = "Hello World") message: String): Map { applicationEventPublisher.publishEvent(MessageCreatedEvent(message)) @@ -43,6 +44,7 @@ class HelloController( } @GetMapping("/stream/chat", produces = ["text/event-stream"]) + @CrossOrigin(value = ["*"]) fun streamChat(): Flux { return this.events.map { event -> try {