本文整理汇总了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));
}
示例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);
}
示例3: streamEvents
@GetMapping(path = "/events", produces = { //
MediaType.APPLICATION_STREAM_JSON_VALUE, //
MediaType.TEXT_EVENT_STREAM_VALUE //
})
Flux<Event> streamEvents() {
return eventRepository.findPeopleBy();
}
示例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();
}
示例5: messages
@GetMapping(value = "/gitter/messages", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ResponseBody
public Flux<GitterMessage> messages() {
return gitterClient.streamMessages(props.getChatRoom());
}
示例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();
}
示例7: tweets
@GetMapping(value = "/tweets", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ResponseBody
Flux<Tweet> tweets() {
return repo.findWithTailableCursorBy();
}