Example usage for org.springframework.http MediaType TEXT_EVENT_STREAM_VALUE

List of usage examples for org.springframework.http MediaType TEXT_EVENT_STREAM_VALUE

Introduction

In this page you can find the example usage for org.springframework.http MediaType TEXT_EVENT_STREAM_VALUE.

Prototype

String TEXT_EVENT_STREAM_VALUE

To view the source code for org.springframework.http MediaType TEXT_EVENT_STREAM_VALUE.

Click Source Link

Document

A String equivalent of MediaType#TEXT_EVENT_STREAM .

Usage

From source file:com.github.danielfernandez.matchday.web.controller.MatchController.java

@RequestMapping(value = "/match/{matchId}/statusStream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public String matchStatusStream(@PathVariable String matchId, final Model model) {

    // Get the stream of MatchStatus objects, based on a tailable cursor.
    // See https://docs.mongodb.com/manual/core/tailable-cursors/
    final Flux<MatchStatus> statusStream = this.matchStatusRepository.tailMatchStatusStreamByMatchId(matchId);

    // Create a data-driver context variable that sets Thymeleaf in data-driven mode
    // in order to produce (render) Server-Sent Events as the Flux produces values.
    // This object also works as wrapper that avoids Spring WebFlux trying to resolve
    // it completely before rendering the HTML.
    final IReactiveSSEDataDriverContextVariable statusDataDriver = new ReactiveDataDriverContextVariable(
            statusStream, 1); // buffers size = 1

    // Add the stream as a model attribute
    model.addAttribute("statusStream", statusDataDriver); // Flux wrapped in a DataDriver to avoid resolution

    // Will use the same "match" template, but only a fragment: the matchStatus block.
    return "match :: #matchStatus";

}

From source file:com.github.danielfernandez.matchday.web.controller.MatchController.java

@ResponseBody // The response payload for this request will be rendered in JSON, not HTML
@RequestMapping(value = "/match/{matchId}/commentStream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<MatchComment> matchCommentStream(@PathVariable String matchId, @RequestParam String timestamp) {

    // Get the stream of MatchComment objects after the timestamp, based on a tailable cursor.
    // See https://docs.mongodb.com/manual/core/tailable-cursors/
    return this.matchCommentRepository.findByMatchIdAndTimestampGreaterThan(matchId, timestamp);

}

From source file:org.springframework.cloud.netflix.turbine.stream.TurbineController.java

@GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> stream() {
    return this.flux;
}