Slide 1

Slide 1 text

Plasma gRPC streamΛར༻ͨ͠ϦΞϧλΠϜͳϢʔβʔମݧ 2018.8.30 THU - 9.2 SUN iOSDC Japan 2018 #iosdc Ryo Aoyama - @ra1028fe5

Slide 2

Slide 2 text

PROFILE Ryo Aoyama CyberAgent, Inc FRESH LIVE iOS Tech Lead CATS (Client Advanced Technology Studio) GitHub: ra1028 Twitter: @ra1028fe5

Slide 3

Slide 3 text

GITHUB

Slide 4

Slide 4 text

ܳೳਓɾ༗໊ਓͳͲͷ഑৴ऀ͕։ઃ͢Δνϟϯωϧͷੜ์ૹΛࢹௌ͠ͳ͕Βίϝϯτ ͳͲͷίϛϡχέʔγϣϯΛָ͠Ή͜ͱ͕Ͱ͖ΔɺϥΠϒ഑৴αʔϏε

Slide 5

Slide 5 text

ຊ୊΁

Slide 6

Slide 6 text

Q. αʔόʔͷঢ়ଶมԽݕ஌ Ͳ͏΍ͬͯ·͔͢ʁ

Slide 7

Slide 7 text

༷ʑͳΫϥΠΞϯτ͔Βਵ࣌ߋ৽͞ΕΔσʔλͷঢ়ଶ ͦΕΛͰ͖ΔݶΓϦΞϧλΠϜʹදࣔߋ৽͢Δʹ͸...

Slide 8

Slide 8 text

ϙʔϦϯά...?

Slide 9

Slide 9 text

ঢ়ଶ͕มΘ͍ͬͯͳͯ͘΋ɺଟ͘ͷແବͳϦΫΤετ͕ൃੜ... ΑΓྑ͍खஈͰঢ়ଶมԽΛݕ஌͍ͨ͠

Slide 10

Slide 10 text

ൃ଍

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

PLASMA gRPC streamΛར༻ͨ͠Go੡Server Pushϛυϧ΢ΣΞ SwiftGRPCΛϥοϓͨ͠iOS༻ΫϥΠΞϯτPlasmaSwift https://github.com/openfresh/plasma https://github.com/openfresh/PlasmaSwift

Slide 13

Slide 13 text

PLASMA HTTP/2ϕʔεͰ͋ΔgRPC͕αϙʔτ͢Δ4छྨͷ௨৴ํࣜ Unary RPC (1 Request - 1 Response) Server streaming RPC (1 Request - Multi Response) Client streaming RPC (Multi Request - 1 Response) Bidirectional streaming RPC (Multi Request - Multi Response)

Slide 14

Slide 14 text

PLASMA gRPC Bidirectional Streaming ʹ 1ͭͷTCPίωΫγϣϯͰෳ਺ͷRequest/Response ͜ΕΛར༻ͯ͠Server Pushܕͷσʔλ௨৴ Λߦ͏൚༻ϛυϧ΢ΣΞ

Slide 15

Slide 15 text

ΫϥΠΞϯτଆ͔Βߋ৽Λड͚औΓ͍ͨλΠϛϯάͰΠϕϯτλΠϓ Λࢦఆͯ͠Subscribe͠ɺ༷ʑͳλΠϛϯάͰPayloadΛड͚औΕΔ

Slide 16

Slide 16 text

PLASMA ྫ͑͹micro servicesؒͰͷϦΫΤετ਺࡟ݮͳͲɺ ΫϥΠΞϯτʹݶΒͣ޿͘ར༻Ͱ͖Δɻ ࠓճ͸iOSͰͷར༻ʹ͍ͭͯ

Slide 17

Slide 17 text

PLASMA gRPCΛ࢖ͬͨߪಡɾ੾அॲཧ͸iOS༻ϥΠϒϥϦͷ PlasmaSwift͕αϙʔτ Objective-C޲͚gRPCʹґଘ͍͕ͯͨ͠ɺ2018/07ʹ SwiftGRPCґଘʹ࡮৽

Slide 18

Slide 18 text

PLASMASWIFT ओͳ໾ׂ ഉଞ੍ޚͭͭ͠઀ଓɾ੾அ௨৴ͷ஥հͱঢ়ଶอ࣋ ઀ଓ͕ҙਤͤͣ੾அͨ͠৔߹͸ɺࣗಈͰϦτϥΠ

Slide 19

Slide 19 text

PLASMASWIFT SwiftGRPCΛར༻ͨ͠Bidirectional streamingͰ͸ɺSubscribe தʹ௨৴ঢ়ଶ͕มΘͬͨ࣌ʹɺϨεϙϯε΋Τϥʔ΋དྷͳ͘ͳ Δ৔߹͕͋ͬͨ ⚠ SystemConfigurationͷSCNetworkReachabilityΛ࢖ͬͯ௨৴ ͷ؂ࢹͱ࠶઀ଓ΋PlasmaSwiftͰΑ͠ͳʹ ͜ͷํ๏͕ਖ਼͍͔͠Ͳ͏͔͸...

Slide 20

Slide 20 text

PLASMASWIFT enum EventType: RawRepresentable { case stats(programId: String) var rawValue: String { /* return event type string */ } init?(rawValue: String) { /* parse payloads */ } } let eventTypes: [EventType] let rawEventTypes = eventTypes.map { $0.rawValue } let client = PlasmaClient(host: host, port: port) client.subscribe(eventTypes: rawEventTypes, retryCount: 10) { event in switch event { case .next(let payload): // Do something case .error(let error): // Error handling } } Subscribe͢ΔΠϕϯτͷఆٛ ResultͷΑ͏ͳenumͰ஋͕౉͞ΕΔ

Slide 21

Slide 21 text

PLASMASWIFT ServerɾClientؒͰReactiveʹΠϕϯτ͕఻ൖ͞ΕΔ ౰વReactiveSwift / RxSwiftͱͷ૬ੑ΋ ReactiveΛར༻ͨ͠ΞϓϦΞʔΩςΫνϟʹೃછΉ

Slide 22

Slide 22 text

ͲΜͳͱ͖ʹ࢖͏ͷ͔

Slide 23

Slide 23 text

ྫ͑͹ɺࢹௌऀͷಈ޲ΛϦΞϧλΠϜʹද͍ࣔͨ࣌͠

Slide 24

Slide 24 text

ࢹௌ਺ ίϝϯτ਺ Ԡԉ

Slide 25

Slide 25 text

ࢹௌ਺ ίϝϯτ਺ Ԡԉ ഑৴ͷϥΠϒײΛߴΊΔͨΊɺಈըҎ֎ ΋ϦΞϧλΠϜʹߋ৽͢Δ ಈը͚ͩͰ΋ෛՙ͕ߴ͍ͷͰɺPlasmaΛ ࢖ͬͯ࠷খݶͷϦιʔεͰ࣮ݱ

Slide 26

Slide 26 text

ྫ͑͹ɺ഑৴ऀͷઃఆͰ͙͢ʹࢹௌऀଆʹ Կ͔Λද͍ࣔͨ࣌͠

Slide 27

Slide 27 text

Ξϯέʔτ ςϩοϓ

Slide 28

Slide 28 text

Ξϯέʔτ ςϩοϓ ಈըͷਐߦʹ߹Θͤͯɺ഑৴Ϣʔβʔ͕ઃ ఆ͢Δͱɺଈ࣌ʹ൓өͤ͞Δඞཁ͕͋Δ

Slide 29

Slide 29 text

ҙ֎ͱখ͍͞...ʁ

Slide 30

Slide 30 text

খ͍͔͞Βͦ͜ʂ খ͍͞୔ࢁͷػೳʹແବͳϦιʔεΛׂ͔ͳ͍

Slide 31

Slide 31 text

CONCLUSIONS Plasma͸gRPCϕʔεͰBidirectional StreamingΛ ར༻ͨ͠൚༻ϛυϧ΢ΣΞ class Plasma: gRPC PlasmaSwiftΛར༻͢Ε͹iOS͔Β࢖͍΍͘͢ Reactiveͱͷ૬ੑ΋ αʔόʔϓογϡʹΑΔΠϕϯτ഑৴͸ɺ։ൃऀΛ ॿ͚Δ͚ͩͰͳ͘ɺύϑΥʔϚϯε΍UXͷ޲্ʹܨ͕Δ

Slide 32

Slide 32 text

Thanks GitHub: ra1028 Twitter: @ra1028fe5