21
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Apache Geode でででで Spring Data Gemfire Pivotal ジジジジジジジジ ジジジジジジジジジジジジジジ ジジ ジジ @quitada

Apache Geode で始めるSpring Data Gemfire

Embed Size (px)

Citation preview

Page 1: Apache Geode で始めるSpring Data Gemfire

Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode で始めるSpring Data Gemfire

Pivotal ジャパン株式会社 テクニカルサポートエンジニア 北田 顕啓@quitada

Page 2: Apache Geode で始めるSpring Data Gemfire

2 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

アジェンダ Apache Geode とは? Spring Data Gemfire とは? Apache Geode で Spring Data Gemfire を使う 最後に…

Page 3: Apache Geode で始めるSpring Data Gemfire

3 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode とは?

Page 4: Apache Geode で始めるSpring Data Gemfire

4 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode とは? Pivotal 社のインメモリデータグリッド製品、 Pivotal GemFire のオープン

ソース版

• 2016 年 3 月現在、 Apache Geode と Pivotal GemFire の差は C#/C++ クライアントモジュール( Native Client 、後述)の有無のみ

インメモリデータグリッド製品 Pivotal GemFire とは? *• スケールアウトする豪華な HashMap に対して…

• SQL ライクなオブジェクトクエリーとか、コンティニュアスクエリー(後述)とかできます

• データをディスクに永続化とかできます→ NoSQL サーバーとしての側面

• MapReduce 的な処理ができます(ファンクション)

• 柔軟な構成がとれます〜 peer-to-peer 、 Client-Server (後述)、 WAN Gateway• 同期&非同期イベント処理(後述)ができます

• 様々なアクセス手段を提供します(独自 API 、 Memcached 、 REST API )

*= 個人の感想です

Page 5: Apache Geode で始めるSpring Data Gemfire

5 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Pivotal GemFire の構成例〜 Client-Server 構成

GemFire のキャッシュを専用サーバーとして起動、データやイベント処理をクライアントより行う→ Geode も同様の構成が可能

用語

• メンバー:データ格納プロセス

• キャッシュ:データ格納先

• 分散システム:クラスターのこと

• リージョン:データ格納テーブル

• キャッシュサーバー:データサーバー

• プール:サーバーへの接続プール

分散システム

キャッシュ

リージョン

リージョン

キャッシュサーバー

キャッシュ

リージョン

リージョン

キャッシュサーバー

キャッシュ

リージョン

リージョン

キャッシュサーバー

メンバー群

Javaクライアント

C#クライアント

C++クライアント

プール プール プール

RESTクライアント

Memcached

クライアント

Native Client( Geode にはない)

Page 6: Apache Geode で始めるSpring Data Gemfire

6 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode の特徴的な機能〜イベント処理

Geode の各種処理に伴いイベントが発生• RegionEvent 、 EntryEvent 、 TransactionEvent 、 CqEvent 、 GatewayEvent…

サブスクリプションによるイベントメッセージ受信設定

• インタレストの登録による受信イベントフィルタリング

• クライアントは受信イベント種別を細かく設定可能

低レイテンシ(ミリ秒以下)

受信イベントに応じた処理駆動〜 **Listener

高可用性・耐障害性

Geode 1 Geode n…

インタレスト登録

Page 7: Apache Geode で始めるSpring Data Gemfire

7 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode の特徴的な機能〜コンティニュアスクエリー( CQ ) サーバーサイドイベントをオブジェクト

クエリーで直接フィルタリングを行い、クライアントで選択的に受信

クエリーはサーバーサイドに配備され、データ更新の度に評価され、条件を満たす イベントのみクライアントに送信

クライアントでイベント受信時にCQListener が駆動され、各種関連ロジックの実行が可能

Geode キャッシュサーバーリージョン

Geode クライアント

ローカルキャッシュ

データ更新

対象リージョンにおいて、クエリーにヒットする

データが更新

CQ リスナーに CQイベントを送信

プールSELECT * FROM /Stock

WHERE ticker = ‘GPV’ and price > 20

Page 8: Apache Geode で始めるSpring Data Gemfire

8 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

<client-cache …> <pool name=”myPool" subscription-enabled="true"> <locator host="172.16.227.2" port="55221"/> </pool> <region name=“myRegion" refid="CACHING_PROXY"> <region-attributes pool-name=”myPool"> <cache-listener> <class-name>io.pivotal.akitada.SimpleCacheListener</class-name> </cache-listener> </region-attributes> </region></client-cache>

Apache Geode でクライアントプログラミング

ソースコード

キャッシュ設定ファイル( client-cache.xml )

ClientCache cache = new ClientCacheFactory() .set("cache-xml-file", "client-cache.xml")       .create();Region<String, String> region = cache.getRegion(“myRegion");region.put(“key1”, “value1”);

クライアントキャッシュ生成

(サーバーアクセスのために

必要)

アクセス先のリージョン取得

生成プール情報(分散システム接続情報)

リージョン情報(プール名指定、

キャッシュリスナー付与)

データ put

Page 9: Apache Geode で始めるSpring Data Gemfire

9 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

(参考) SnppyData 〜もう一つの GemFire オープンソース製品

2016 年 1 月に、 Pivotal からスピンアウトしたSnappyData 社よりリリース

Pivotal GemFire をベースに、 HDFS データストア連携、SQL インターフェース、 Spark 、 AQP ( ApproximateQuery Processing )技術を実装した、 OLAP + OLTP基盤

2016 年 3 月現在、 v0.1 preview バージョンがリリース済み

URL: http://www.snappydata.com

Page 10: Apache Geode で始めるSpring Data Gemfire

10 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Demo

Unless otherwise indicated, these slides are© 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense:http://creativecommons.org/ licenses/by-nc/3.0/

gfsh によるGeode 分散システムの起動、データ操作

Apache Geode

Page 11: Apache Geode で始めるSpring Data Gemfire

11 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Spring Data Gemfire とは?

Page 12: Apache Geode で始めるSpring Data Gemfire

12 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Spring Data Gemfire とは?( 1/2 )

Spring Data とは?• あらゆるデータソースに対して Spring フレームワークベースの一貫した容易なアクセス手段を提供

Spring Data Gemfire は Spring Data の “ umbrella project”• Spring による GemFire リソースの生成・設定を行う XML ネームスペースのサポート• GemFire の Spring Data Repositories による抽象化• アノテーションベースのファンクション実行• インタレスト登録、コンティニュアス・クエリーの xml 設定

サポート

• Spring Data GemFire 1.7 より、 Apache Geode サポート

Page 13: Apache Geode で始めるSpring Data Gemfire

13 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Spring Data Gemfire によるコーディング例( 1/2 ) 再掲) Geode API を用いたクライアント実装

ClientCache cache = new ClientCacheFactory() .set("cache-xml-file", "client-cache.xml")       .create();Region<String, String> region = cache.getRegion(“myRegion");region.put(“key1”, “value1”);

<client-cache …> <pool name=”myPool" subscription-enabled="true"> <locator host="172.16.227.2" port="55221"/> </pool> <region name=“myRegion" refid="CACHING_PROXY"> <region-attributes pool-name=”myPool"> <cache-listener> <class-name>io.pivotal.akitada.SimpleCacheListener</class-name> </cache-listener> </region-attributes> </region></client-cache>

ソースコード

キャッシュ設定ファイル

Page 14: Apache Geode で始めるSpring Data Gemfire

14 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Spring Data Gemfire によるコーディング例( 2/2 ) Spring Data Gemfire を用いたクライアント実装

ApplicationContext context= new ClassPathXmlApplicationContext("META-INF/path-to/cache-config.xml");Region<String,String> region = context.getBean(Region.class);region.put("key1", "value1");

<beans ...> <gfe-data:datasource subscription-enabled="true"> <gfe-data:locator host="172.16.9.1" port="55221" /> </gfe-data:datasource> <gfe:client-region id="myRegion” shortcut="CACHING_PROXY"> <gfe:cache-listener> <bean class="io.pivotal.akitada.SimpleCacheListener" /> </gfe:cache-listener> </gfe:client-region></beans>

ソースコード

キャッシュ設定ファイル

Page 15: Apache Geode で始めるSpring Data Gemfire

15 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode でSpring Data Gemfire を使う

Page 16: Apache Geode で始めるSpring Data Gemfire

16 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

STS を使って Apache Geode + Spring Data Gemfire でアプリ開発 STS とは? = Spring Tool Suite• Java IDE Eclipse ベースの Spring

アプリケーション開発ツールスイート

• http://spring.io/tools

• 豊富な Spring プロジェクトテンプレート• すぐに Spring ベースの開発が始められる

• Spring Data GemFire のプロジェクトテンプレートも用意

• 無償提供• Pivotal による有償サポートも提供( Spring Enterprise Support )

Page 17: Apache Geode で始めるSpring Data Gemfire

17 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode + Spring Data Gemfire プロジェクトの作成

STS で Spring Data Gemfire プロジェクトを作成

• File > New > Spring Legacy Project にてダイアログ表示

• Templates: にて GemFire テンプレートから何か選択(例えば、 Spring Data GemFire Client Project )

• Maven プロジェクトを作成

pom.xml の編集<properties> <spring.data.gemfire.version>1.7.4.RELEASE</spring.data.gemfire.version> :<dependencies> <dependency> <groupId>org.apache.geode</groupId> <artifactId>gemfire-core</artifactId> <version>1.0.0-incubating.M1</version> </dependency>

最新版 Spring Data Gemfire のバージョンを指定

dependencies の先頭( Spring Data GemFire よ

りも前)に、 Geode の dependency を追加

Page 18: Apache Geode で始めるSpring Data Gemfire

18 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Demo

Unless otherwise indicated, these slides are© 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense:http://creativecommons.org/ licenses/by-nc/3.0/

Spring Data Gemfire をちょっと使った CacheListener のデモ

Apache Geode + Spring Data Gemfire

Page 19: Apache Geode で始めるSpring Data Gemfire

19 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

最後に…

Page 20: Apache Geode で始めるSpring Data Gemfire

20 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

今日のまとめとやり残したこと

今日のまとめ

• Apache Geode の概要紹介

• Spring Data Gemfire の概要紹介

• Apache Geode + Spring Data Gemfire によるアプリケーション開発事始め

やり残したこと• Apache Geode と Apache Ignite

の比較

• JavaConfig を使ったキャッシュの設定

• アノテーションを使った Spring 的なプログラミングの探求

Page 21: Apache Geode で始めるSpring Data Gemfire

21 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial l icense: http://creat ivecommons.org/ licenses/by-nc/3.0/

Apache Geode / Spring Data Gemfire – 技術情報

Spring Data Gemfire supports Apache Geode• https://spring.io/blog/2015/06/12/spring-data-gemfire-supports-apache-geode

GitHub – spring-projects/spring-gemfire-examples: サンプルコード

• https://github.com/spring-projects/spring-gemfire-examples

Apache Geode: プロジェクトホーム

• http://geode.incubator.apache.org/

Spring Data Gemfire: プロジェクトホーム

• http://projects.spring.io/spring-data-gemfire/

今回使用したデモ用アプリケーションプロジェクト一式

• https://github.com/AkihiroKitada/MySpringDataGemfireSamples