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
44
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
57
Reactive Programming no mundo Java
ftmamud
0
190
Reactive Programming - Brincando com eficiência, composição e assíncronia
ftmamud
1
500
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
89
Other Decks in Programming
See All in Programming
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.3k
php-conference-japan-2024
tasuku43
0
410
MCP with Cloudflare Workers
yusukebe
2
270
為你自己學 Python
eddie
0
500
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
220
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
230
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
410
Beyond ORM
77web
11
1.5k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
790
良いユニットテストを書こう
mototakatsu
11
3.5k
快速入門可觀測性
blueswen
0
480
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
500
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Scaling GitHub
holman
459
140k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Docker and Python
trallard
43
3.2k
What's in a price? How to price your products and services
michaelherold
244
12k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
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