2017-11-19 1 views
0

サーバーサイドイベント経由でストリーミングデータを受信する方法Content-Type: text/event-stream Spring Flux機能を使用していますか? WebClientでこのような応答を処理することは可能ですか?Springリアクティブ処理サーバーのサイドイベント

ソースエンドポイント:

@GetMapping(path = "/", produces = MediaType.TEXT_EVENT_STREAM_VALUE) 
public Flux<CurrencyStats> get() { 
    return getStream(); 
} 

私は、データをそのようを取得しようとしましたが、間違っているようです。私は必要なものである

WebClient webClient = WebClient.create("http://example.com"); 
     return webClient 
       .get() 
       .uri("/sse") 
       .accept(MediaType.TEXT_EVENT_STREAM) 
       .retrieve() 
       .bodyToFlux(String.class).doOnNext(
         string -> { 
          // print that string 
         } 
       ); 

答えて

0

WebClient webClient = WebClient.create(url); 
     Flux<Map> alerts = webClient.get() 
       .uri("/sse") 
       .accept(MediaType.TEXT_EVENT_STREAM) 
       .retrieve() 
       .bodyToFlux(Map.class) 
       .checkpoint().doOnNext(
         s -> { 
          logger.log(Level.ERROR, s); 
         } 
       ); 
関連する問題