当前位置: 首页>>代码示例>>Java>>正文


Java MediaType.TEXT_EVENT_STREAM_VALUE属性代码示例

本文整理汇总了Java中org.springframework.http.MediaType.TEXT_EVENT_STREAM_VALUE属性的典型用法代码示例。如果您正苦于以下问题:Java MediaType.TEXT_EVENT_STREAM_VALUE属性的具体用法?Java MediaType.TEXT_EVENT_STREAM_VALUE怎么用?Java MediaType.TEXT_EVENT_STREAM_VALUE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.springframework.http.MediaType的用法示例。


在下文中一共展示了MediaType.TEXT_EVENT_STREAM_VALUE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: streamTightCouplingEvents

@GetMapping(value = "/projects/{projectId}/tightCouplingEvents", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ServerSentEvent<TightCouplingEvent>> streamTightCouplingEvents(@PathVariable Long projectId,
                                                                           HttpServletRequest request) {
    // Stream the events from MongoDB
    Flux<TightCouplingEvent> events = eventRepository.findByProjectId(projectId);

    // Check if this is an SSE reconnection from a client
    String lastEventId = request.getHeader("Last-Event-Id");

    // On SSE client reconnect, skip ahead in the stream to play back only new events
    if (lastEventId != null)
        events = events.skipUntil(e -> e.getId().equals(lastEventId)).skip(1);

    // Subscribe to the tailing events from the reactive repository query
    return events.map(s -> ServerSentEvent.builder(s)
            .event(s.getCreatedDate().toString())
            .id(s.getId())
            .build())
            .delayElements(Duration.ofMillis(100));
}
 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:20,代码来源:ViewController.java

示例2: sse

@GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Post> sse() {
    return Flux
            .zip(Flux.interval(Duration.ofSeconds(1)), this.posts.findAll().repeat())
            .map(Tuple2::getT2);
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:6,代码来源:PostController.java

示例3: streamEvents

@GetMapping(path = "/events", produces = { //
		MediaType.APPLICATION_STREAM_JSON_VALUE, //
		MediaType.TEXT_EVENT_STREAM_VALUE //
})
Flux<Event> streamEvents() {
	return eventRepository.findPeopleBy();
}
 
开发者ID:olivergierke,项目名称:spring-five-functional-reactive,代码行数:7,代码来源:EventController.java

示例4: getInfiniteStreamOfConfigurationsDelayed

/**
 * infinite stream of configuration id and configuration name.
 * print a configuration every second.
 * repeat if end of Flux is reached.
 */
@GetMapping(value = "infiniteStream/{seconds}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Tuple2<Long, String>> getInfiniteStreamOfConfigurationsDelayed(@PathVariable Long seconds) {
    return Flux.interval(Duration.ofSeconds(1))
            .zipWith(repository.findAll().delayElements(Duration.ofSeconds(seconds)).map(t -> "id: " + t.getId() + " :: " + t.getName()))
            .repeat()
            .log();
}
 
开发者ID:nkolytschew,项目名称:blog_post_examples,代码行数:12,代码来源:ConfigurationReactiveController.java

示例5: messages

@GetMapping(value = "/gitter/messages", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ResponseBody
public Flux<GitterMessage> messages() {
    return gitterClient.streamMessages(props.getChatRoom());
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:5,代码来源:IndexController.java

示例6: getConfigurationListAsDelayedStream

/**
 * get all configuration as stream. with a delay of X seconds
 */
@GetMapping(value = "stream/delayed/{seconds}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ConfigurationDocument> getConfigurationListAsDelayedStream(@PathVariable Long seconds) {
    return repository.findAllByOrderByNameDesc().delayElements(Duration.ofSeconds(seconds)).log();
}
 
开发者ID:nkolytschew,项目名称:blog_post_examples,代码行数:7,代码来源:ConfigurationReactiveController.java

示例7: tweets

@GetMapping(value = "/tweets", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ResponseBody
Flux<Tweet> tweets() {
    return repo.findWithTailableCursorBy();
}
 
开发者ID:orlandovald,项目名称:webflux-twitter-demo,代码行数:5,代码来源:TweetController.java


注:本文中的org.springframework.http.MediaType.TEXT_EVENT_STREAM_VALUE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。