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
45
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
55
Groovy como você nunca viu
ftmamud
0
2.3k
Erlang sem enrolação!
ftmamud
0
110
Gradle: o melhor amigo no build do seu software
ftmamud
0
120
Desenvolvendo software no mundo atual
ftmamud
0
57
Reactive Programming no mundo Java
ftmamud
0
190
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
520
Concorrência em Java: do velho oeste a atualidade
ftmamud
0
100
Java Threads: O que há de errado com elas e como resolver?
ftmamud
0
90
Other Decks in Programming
See All in Programming
読まないコードリーディング術
hisaju
0
110
推しメソッドsource_locationのしくみを探る - はじめてRubyのコードを読んでみた
nobu09
2
330
color-scheme: light dark; を完全に理解する
uhyo
7
500
Ça bouge du côté des animations CSS !
goetter
2
150
PEPCは何を変えようとしていたのか
ken7253
3
280
データベースのオペレーターであるCloudNativePGがStatefulSetを使わない理由に迫る
nnaka2992
0
240
SwiftUI Viewの責務分離
elmetal
PRO
2
280
Datadog Workflow Automation で圧倒的価値提供
showwin
1
260
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
8
1.5k
CloudNativePGを布教したい
nnaka2992
0
120
15分で学ぶDuckDBの可愛い使い方 DuckDBの最近の更新
notrogue
3
700
技術を改善し続ける
gumioji
0
140
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
A Tale of Four Properties
chriscoyier
158
23k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Building Applications with DynamoDB
mza
93
6.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Building Your Own Lightsaber
phodgson
104
6.2k
Unsuck your backbone
ammeep
669
57k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Code Reviewing Like a Champion
maltzj
521
39k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
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