Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Criando um endpoint de streaming
Search
Felipe Mamud
October 19, 2017
Programming
1
57
Criando um endpoint de streaming
Como criar um endpoint stream utilizando Spring Boot.
Felipe Mamud
October 19, 2017
Tweet
Share
More Decks by Felipe Mamud
See All by Felipe Mamud
Criando sua DSL com jparsec
ftmamud
0
77
Groovy como você nunca viu
ftmamud
0
2.3k
Erlang sem enrolação!
ftmamud
0
130
Gradle: o melhor amigo no build do seu software
ftmamud
0
120
Desenvolvendo software no mundo atual
ftmamud
0
86
Reactive Programming no mundo Java
ftmamud
0
210
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
580
Concorrência em Java: do velho oeste a atualidade
ftmamud
0
110
Java Threads: O que há de errado com elas e como resolver?
ftmamud
0
100
Other Decks in Programming
See All in Programming
開発組織の戦略的な役割と 設計スキル向上の効果
masuda220
PRO
10
2k
SODA - FACT BOOK(JP)
sodainc
1
9.1k
iOSでSVG画像を扱う
kishikawakatsumi
0
180
モテるデスク環境
mozumasu
3
1.4k
KoogではじめるAIエージェント開発
hiroaki404
1
230
AI駆動開発カンファレンスAutumn2025 _AI駆動開発にはAI駆動品質保証
autifyhq
0
110
AIのバカさ加減に怒る前にやっておくこと
blueeventhorizon
0
130
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
200
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
660
オンデバイスAIとXcode
ryodeveloper
0
370
CSC509 Lecture 07
javiergs
PRO
0
250
Google Opal解体新書
mickey_kubo
3
110
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
34
8.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Become a Pro
speakerdeck
PRO
29
5.6k
Documentation Writing (for coders)
carmenintech
76
5.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
Transcript
Criando um endpoint de streaming DANIEL MEZZATTO @mezzatto FELIPE MAMUD
@mamud
Então vc quer criar um endpoint stream?
AGENDA Stream.of("Motivação", "Desafios", "Endpoint") .map(VivaReal::techTalk) .collect(Collectors.knowledge());
MOTIVAÇÃO • Time to first byte (TTFB) • Deep paging
DESAFIOS • Qual implementação utilizar? ◦ Java? outra linguagem? ◦
Server-Sent Events ◦ StreamingResponseBody* ◦ Custom • ES SearchScroll (com shards) • Sized stream
CONTROLLER @RequestMapping(value = "/{index}/stream", method = GET) public StreamingResponseBody stream(
FilterableApiRequest request, HttpServletResponse httpServletResponse) { httpServletResponse .setContentType("application/x-ndjson;charset=UTF-8"); return out -> searchService.stream(request, out); }
@Component public class ElasticSearchStream { public void stream(OutputStream stream) {
ResponseStream.iterate(stream, new SearchApiIterator<>(esClient, requestBuilder(), scroll -> scroll.setScroll(keepAlive) .actionGet(streamTimeout), count), searchHit -> toBytes(searchHit.getSourceRef())); } } ELASTICSEARCH STREAM
RESPONSE STREAM public static <T> void iterate(OutputStream stream, Iterator<T[]> iterator,
Function<T, byte[]> byteFn) { while (iterator.hasNext()) { for (T hit: iterator.next()) { stream.write(byteFn.apply(hit)); stream.write('\n'); } stream.flush(); } }
SEARCH ITERATOR public class SearchApiIterator<T> implements Iterator<T[]> { @Override public
boolean hasNext() { return hits() > 0 && count <= size; } @Override public T[] next() { T[] result = (T[]) response.getHits().getHits(); response = loop.apply(client.prepareSearchScroll(response.getScrollId())); this.count += hits(); return result; } }|
None