This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | data class Tweet( | |
| @JsonProperty("uuid") | |
| val uuid: String = UUID.randomUUID().toString(), | |
| @JsonProperty("text") | |
| val text: String, | |
| @JsonProperty("at") | |
| val at: ZonedDateTime = ZonedDateTime.now(ZoneId.of("UTC")) | |
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | fun stream(serverRequest: ServerRequest) = | |
| ServerResponse | |
| .ok() | |
| .sse() | |
| .body( | |
| tweetRepository | |
| .listen() | |
| .asPublisher() | |
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | fun publish(monoTweet: Mono<Tweet>) = | |
| monoTweet | |
| .flatMap { | |
| redisTemplate | |
| .convertAndSend( | |
| TWEET_CHANNEL, | |
| it // it: Tweet! | |
| ) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | fun listen(): Flow<Tweet> = | |
| redisTemplate | |
| .listenToChannelAsFlow( | |
| TWEET_CHANNEL | |
| ) | |
| .map { | |
| it.message // it: reactiveSubscription.Message<String, Tweet!> | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @Bean | |
| fun routes(tweetHandler: TweetHandler) = | |
| router { | |
| accept(MediaType.APPLICATION_JSON) | |
| .nest { | |
| POST("/tweet", | |
| tweetHandler::tweet) | |
| } | |
| accept(MediaType.TEXT_EVENT_STREAM) | |
| .nest { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "annotations": { | |
| "list": [ | |
| { | |
| "builtIn": 1, | |
| "datasource": "-- Grafana --", | |
| "enable": true, | |
| "hide": true, | |
| "iconColor": "rgba(0, 211, 255, 1)", | |
| "name": "Annotations & Alerts", | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.josefigueredo.examples.waysofroute.router | |
| import com.josefigueredo.examples.waysofroute.handler.ReactiveHandler | |
| import org.springframework.beans.factory.annotation.Autowired | |
| import org.springframework.context.annotation.Bean | |
| import org.springframework.http.MediaType.TEXT_HTML | |
| import org.springframework.stereotype.Component | |
| import org.springframework.web.reactive.function.server.router | |
| @Component | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.josefigueredo.examples.waysofroute.router | |
| import com.josefigueredo.examples.waysofroute.handler.CoroutineHandler | |
| import org.springframework.beans.factory.annotation.Autowired | |
| import org.springframework.context.annotation.Bean | |
| import org.springframework.http.MediaType.TEXT_HTML | |
| import org.springframework.stereotype.Component | |
| import org.springframework.web.reactive.function.server.coRouter | |
| @Component | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.josefigueredo.examples.waysofroute.router | |
| import com.josefigueredo.examples.waysofroute.handler.ReactiveHandler | |
| import kotlinx.coroutines.flow.Flow | |
| import org.springframework.beans.factory.annotation.Autowired | |
| import org.springframework.http.MediaType | |
| import org.springframework.web.bind.annotation.* | |
| @RestController | |
| @RequestMapping("/annotated-reactive") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.josefigueredo.examples.waysofroute.router | |
| import com.josefigueredo.examples.waysofroute.handler.CoroutineHandler | |
| import kotlinx.coroutines.flow.Flow | |
| import kotlinx.coroutines.flow.first | |
| import org.springframework.beans.factory.annotation.Autowired | |
| import org.springframework.http.MediaType | |
| import org.springframework.web.bind.annotation.* | |
| @RestController |