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
1
43
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
54
Groovy como você nunca viu
ftmamud
0
2.2k
Erlang sem enrolação!
ftmamud
0
100
Gradle: o melhor amigo no build do seu software
ftmamud
0
110
Desenvolvendo software no mundo atual
ftmamud
0
56
Reactive Programming no mundo Java
ftmamud
0
180
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
480
Concorrência em Java: do velho oeste a atualidade
ftmamud
0
99
Java Threads: O que há de errado com elas e como resolver?
ftmamud
0
84
Other Decks in Programming
See All in Programming
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
受け取る人から提供する人になるということ
little_rubyist
0
250
Macとオーディオ再生 2024/11/02
yusukeito
0
380
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
350
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
180
Better Code Design in PHP
afilina
PRO
0
130
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
5
330
Click-free releases & the making of a CLI app
oheyadam
2
120
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Six Lessons from altMBA
skipperchong
27
3.5k
It's Worth the Effort
3n
183
27k
Speed Design
sergeychernyshev
25
620
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
What's in a price? How to price your products and services
michaelherold
243
12k
Side Projects
sachag
452
42k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Done Done
chrislema
181
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Become a Pro
speakerdeck
PRO
25
5k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
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