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
64
1
Share
Criando um endpoint de streaming
Como criar um endpoint stream utilizando Spring Boot.
Felipe Mamud
October 19, 2017
More Decks by Felipe Mamud
See All by Felipe Mamud
Criando sua DSL com jparsec
ftmamud
0
98
Groovy como você nunca viu
ftmamud
0
2.3k
Erlang sem enrolação!
ftmamud
0
140
Gradle: o melhor amigo no build do seu software
ftmamud
0
130
Desenvolvendo software no mundo atual
ftmamud
0
100
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
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
580
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
150
事業会社でのセキュリティ長期インターンについて
masachikaura
0
260
Vibe NLP for Applied NLP
inesmontani
PRO
0
460
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
550
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
750
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
400
実用!Hono RPC2026
yodaka
2
250
AWSコミュニティ活動は顧客のクラウド推進に効くのか / Do AWS community activities help customers adopt the cloud?
seike460
PRO
0
150
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
640
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
3
350
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
0
420
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
170
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
140
The browser strikes back
jonoalderson
0
980
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
170
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
680
Are puppies a ranking factor?
jonoalderson
1
3.3k
Un-Boring Meetings
codingconduct
0
270
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Faster Mobile Websites
deanohume
310
31k
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