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
73
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
110
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
140
Desenvolvendo software no mundo atual
ftmamud
0
110
Reactive Programming no mundo Java
ftmamud
0
220
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
630
Concorrência em Java: do velho oeste a atualidade
ftmamud
0
130
Java Threads: O que há de errado com elas e como resolver?
ftmamud
0
130
Other Decks in Programming
See All in Programming
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
430
さぁV100、メモリをお食べ・・・
nilpe
0
130
RailsTokyo 2026#4: AI様があれば、 Hotwireの弱点は消えるか?
naofumi
5
1k
TSKaigi 2026 TypeScriptバックエンドのオブザーバビリティ戦略 — Datadog × NestJSの実践
taiseiyamamotoan
1
220
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
3
1.4k
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
今さら聞けないCancellationToken
htkym
0
210
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
530
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
440
OSもどきOS
arkw
0
390
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
3
1.2k
Featured
See All Featured
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
560
Marketing to machines
jonoalderson
1
5.3k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
55k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
220
Raft: Consensus for Rubyists
vanstee
141
7.5k
New Earth Scene 8
popppiees
3
2.3k
How to make the Groovebox
asonas
2
2.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
200
74k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
520
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Side Projects
sachag
455
43k
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