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 {