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
82
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
120
Groovy como você nunca viu
ftmamud
0
2.3k
Erlang sem enrolação!
ftmamud
0
150
Gradle: o melhor amigo no build do seu software
ftmamud
0
150
Desenvolvendo software no mundo atual
ftmamud
0
110
Reactive Programming no mundo Java
ftmamud
0
230
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
650
Concorrência em Java: do velho oeste a atualidade
ftmamud
0
140
Java Threads: O que há de errado com elas e como resolver?
ftmamud
0
130
Other Decks in Programming
See All in Programming
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
120
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
0
310
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.8k
typoなんかねぇよ
raspython3
0
600
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
5
1.8k
MySQLとPostgreSQLって何が違うの?
akagami
0
150
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
180
Press start. Python's next generation.
willingc
PRO
3
240
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
180
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
440
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
510
Featured
See All Featured
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
350
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
260
sira's awesome portfolio website redesign presentation
elsirapls
0
350
First, design no harm
axbom
PRO
2
1.3k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
560
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
290
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