RxJava + Vert.x + jOOλ で Microservice的な何かを作ってみた

RxJava + Vert.x + jOOλ で Microservice的な何かを作ってみた

8a43d544df4886ea5ef714e78f3420a7?s=128

Hideyuki Takeuchi

April 28, 2016
Tweet

Transcript

  1. 3.
  2. 6.
  3. 11.

    νϟʔτ༻JSON͕ฦΔ·ͰͷྲྀΕ 1. Media API ͔ΒνϟʔτͷૉΛऔಘ͢Δ 2. νϟʔτͷૉͰࢦఆ͞ΕͨσʔλΛ
 Companies API ΍

    Stats APIʹ
 ෳ਺ճϦΫΤετΛ౤͛ͯऔಘ͢Δ 3. ݁ՌΛ·ͱΊͯJSONʹͯ͠ϒϥ΢βʹฦ͢
  4. 12.
  5. 17.

    Vert.x + Vert.x-Web • ϊϯϒϩοΩϯάI/OͳߴϨϕϧϑϨʔϜϫʔΫ • γϯάϧεϨουͰେྔͷίωΫγϣϯΛ͞͹͚Δ • શ͕ͯίʔϧόοΫͰ݁Ռ͕ฦΔඇಉظAPI •

    Node.js + Express తͳଘࡏ (ͱ͍͏͔·Μ·ͦΕ) • ϚϧνεϨουͰ΋ಈ͘
 Verticleͱ͍͏֓೦ɺEventBusͱ͍͏֓೦
  6. 22.
  7. 23.
  8. 25.

    RxJavaΛ࢖Θͳ͔ͬͨ৔߹(Πϝʔδ) client.getConnection(result1 -> { SQLConnection connection = result1.result(); connection.setAutoCommit(false, result2

    -> { connection.queryWithParams("SELECT ...", params3, result3 -> { connection.updateWithParams("UPDATE ...", params4, result4 -> { connection.commit(result5 -> { connection.close(result6 -> { successCallback(); }); }); }); }); }); }); ΤϥʔॲཧΛೖΕΔͱ΋ͬͱͻͲ͍͜ͱʹɻɻɻ
  9. 26.

    RxJavaΛ࢖ͬͨ৔߹(Πϝʔδ) client.getConnectionObservable().flatMap(connection -> { return connection.setAutoCommitObservable(false) .flatMap(result -> connection.queryWithParamsObservable("SELECT ...",

    params1)) .flatMap(result -> connection.updateWithParamsObservable("UPDATE ...", params2))) .flatMap(result -> connection.commitObservable()) .flatMap(result -> connection.closeObservable()); }); Τϥʔॲཧ͸subscribeͰҰճॻ͚ͩ͘ʂ
  10. 33.

    ࣮ࡍͷྑ͋ͬͨ͘ίʔυ(งғؾ) observableA // Media APIからチャートの素を取得 .flatMap(responseA -> { .. responseAからobservableB,

    C, D (企業B, C, D)を生成 .. return Observable.zip( observableB.map(Optional::of).onErrorReturn(e -> Optional.empty()), observableC.map(Optional::of).onErrorReturn(e -> Optional.empty()), observableD.map(Optional::of).onErrorReturn(e -> Optional.empty()), (optionalResponseB, optionalResponseC, optionalResponseD) -> { .. responseAとoptionalResponseB, C, DからresponseZを生成 .. return responseZ; // チャートのモデル }); });
  11. 40.