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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Felipe Mamud
October 19, 2017
Programming
1
63
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
94
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
130
Desenvolvendo software no mundo atual
ftmamud
0
99
Reactive Programming no mundo Java
ftmamud
0
220
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
620
Concorrência em Java: do velho oeste a atualidade
ftmamud
0
120
Java Threads: O que há de errado com elas e como resolver?
ftmamud
0
120
Other Decks in Programming
See All in Programming
How to stabilize UI tests using XCTest
akkeylab
0
150
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
6
1.1k
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
270
20260315 AWSなんもわからん🥲
chiilog
2
180
条件判定に名前、つけてますか? #phperkaigi #c
77web
2
860
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
300
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
[PHPerKaigi 2026]PHPerKaigi2025の企画CodeGolfが最高すぎて社内で内製して半年運営して得た内製と運営の知見
ikezoemakoto
0
310
ロボットのための工場に灯りは要らない
watany
12
3.2k
AI-DLC 入門 〜AIコーディングの本質は「コード」ではなく「構造」〜 / Introduction to AI-DLC: The Essence of AI Coding Is Not “Code” but “Structure”
seike460
PRO
0
110
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
100
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Believing is Seeing
oripsolob
1
99
A Soul's Torment
seathinner
5
2.5k
A designer walks into a library…
pauljervisheath
210
24k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Un-Boring Meetings
codingconduct
0
240
Reality Check: Gamification 10 Years Later
codingconduct
0
2.1k
The untapped power of vector embeddings
frankvandijk
2
1.6k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.4k
Producing Creativity
orderedlist
PRO
348
40k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.1k
Scaling GitHub
holman
464
140k
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