$30 off During Our Annual Pro Sale. View Details »
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
61
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
84
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
88
Reactive Programming no mundo Java
ftmamud
0
210
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
590
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
110
Other Decks in Programming
See All in Programming
AIコーディングエージェント(NotebookLM)
kondai24
0
180
開発に寄りそう自動テストの実現
goyoki
1
860
20 years of Symfony, what's next?
fabpot
2
350
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
100
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
390
AIコーディングエージェント(skywork)
kondai24
0
160
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
310
TypeScriptで設計する 堅牢さとUXを両立した非同期ワークフローの実現
moeka__c
6
3k
Microservices rules: What good looks like
cer
PRO
0
1.2k
AIコーディングエージェント(Manus)
kondai24
0
170
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
11
11k
Cell-Based Architecture
larchanjo
0
110
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Six Lessons from altMBA
skipperchong
29
4.1k
How GitHub (no longer) Works
holman
316
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
A designer walks into a library…
pauljervisheath
210
24k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
A Tale of Four Properties
chriscoyier
162
23k
Faster Mobile Websites
deanohume
310
31k
Designing Experiences People Love
moore
143
24k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
[SF Ruby Conf 2025] Rails X
palkan
0
500
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
970
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