kagamihogeの日記

kagamihogeの日記です。

Spring Boot

Spring Cloud Circuit Breakerさわる

Spring Cloud Circuit Breaker https://spring.io/projects/spring-cloud-circuitbreaker#overview のチュートリアルレベルのことをやる。 Spring Cloud Circuit Breaker自身は抽象APIを提供するだけで、使う際には具体的な実装を選択する、というタイプ。以…

Spring Cloud Gatewayさわる

https://spring.io/projects/spring-cloud-gateway をさわる。はじめてさわるのでpredicateとかfilterとかをいくつか使ってみる。使い方わからなかったやつはさわってない。個人の日記レベルのさわってみた程度なんで、ちゃんとした情報はリファレンスを参照…

Spring Batch + MySQL + JTA(Atomikos)のUnable to commit new sequence value changes for BATCH_JOB_SEQ

現象 タイトル通りSpring Batch + MySQL + JTA(Atomikos)環境下で以下のような例外がスローされる。 Caused by: org.springframework.dao.DataAccessResourceFailureException: Unable to commit new sequence value changes for BATCH_JOB_SEQ at org.sprin…

Spring Boot 2.2.x + Spring Batchうごかす

Spring Batchのチュートリアル https://spring.io/guides/gs/batch-processing/ を動かします。このサンプルはいわゆるデータインポート処理で、CSVからデータ読み込み・変換・保存、を行います。 プロジェクト作成 Spring Bootの組み込みDB自動設定 build.g…

Spring Batchのstep間データ共有

Spring Batchでstep間でデータを共有する方法について。機能的に豊富では無いが、そこはSpring Batchとして積極的に提供する機能では無い、という設計判断なのだと思う。 以下ではそのやり方について述べる。 JobのExecutionContext JobのExecutionContextに…

Spring Cloud Config + Spring Cloud Busでプロパティ自動更新

http://kagamihoge.hatenablog.com/entry/2020/02/14/091501 ではSpring Cloud Configを試した。問題点としてプロパティの更新がある。/actuator/refreshで1つのclientのリフレッシュは出来るが、100個あったら100回送信しなければならない。その解決方法に…

Spring Cloud Configをためす

Spring Cloud Config を試す。 gitリポジトリの準備 適当なローカルディレクトリとか、GitHubとか、http://kagamihoge.hatenablog.com/entry/2020/02/13/095145 とか、なんでも良いが適当なgitリポジトリを準備する。 プロパティファイルとして/sample.prope…

spring-batchでグループ単位のレコード読み込み

https://terasoluna-batch.github.io/guideline/5.0.0.RELEASE/ja/Ch05_FileAccess.html によると、コントロールブレイク処理(またはキーブレイク処理)、と呼ぶものをspring-batchで実現する方法について。 コントロールブレイク処理(またはキーブレイク処理…

spring-batchのPartitioningをためす

https://docs.spring.io/spring-batch/docs/current/reference/html/scalability.html#partitioning のPartitioningを試す。 ソースコード plugins { id 'org.springframework.boot' version '2.2.2.RELEASE' id 'io.spring.dependency-management' version …

spring-batchのRemote Chunkingをためす

https://docs.spring.io/spring-batch/docs/4.1.x/reference/html/spring-batch-integration.html#remote-chunking のRemote Chunkingをためす。 このサンプルは、Spring Integegration -> Active MQを介してMasterからworkerおprocessor + writerを呼び出す…

Spring BootでApache ActiveMQの送受信

Spring Bootでhttp://activemq.apache.org/を使用しての送受信のhello worldレベルのことをやる。 手順など Apache ActiveMQのインストール http://activemq.apache.org/をインストールする。まずbin/artemis create 名前を実行する。以下はbin/artemis crea…

spring-batchのParallel Stepsをためす

https://docs.spring.io/spring-batch/docs/current/reference/html/scalability.html#scalabilityParallelSteps のパラレルstepを試す。http://kagamihoge.hatenablog.com/entry/2020/01/07/110847 は単一のstepをマルチスレッド化する方法だが、こちらは複…

spring-batchのTaskExecutorによるstepマルチスレッド化

https://docs.spring.io/spring-batch/docs/current/reference/html/scalability.html#scalability のMulti-threaded Stepを試す。 plugins { id 'org.springframework.boot' version '2.2.2.RELEASE' id 'io.spring.dependency-management' version '1.0.8.…

spring-securityのaclをうごかす

spring-securityのDomain Object Security (ACLs)のhelllo world的なとりあえず動くところまでをやる。 ソースコード build.gradle plugins { id 'org.springframework.boot' version '2.2.2.RELEASE' id 'io.spring.dependency-management' version '1.0.8.…

spring-bootでspring-mvcの依存性が解決される仕組みを調べる

spring-bootでは、例えば以下のようにparentとdependencyを指定しておけば、spring-webとかspring-mvcとかの依存性をよしなに解決してくれる。以下のように書くとspring-webmvc-5.2.1.RELEASE.jarが解決されるが、このエントリではそれがどのようにして行わ…

thymeleaf-extras-springsecurityつかう

Thymeleafコアには含まれない、spring-securityとThymeleafを結び付けて使うためのThymeleaf Extrasモジュールの基本的な使い方に関するメモ。基本的に、このエントリは https://github.com/thymeleaf/thymeleaf-extras-springsecurity のドキュメントを基に…

spring-bootでセッション保存先をredisにする

Spring BootでSpring Securityをredisでうごかすでは、spring-securityのセッション保存先をredisに変更した。このエントリはspring-securityを伴わない場合だが、やることはほとんど変わらない。 やること redisのインストール 他サイトを見て適当なマシン…

RedisのKEYSを同時に何個か実行する

RedisのkeysがO(N)を実際に見る で見たようにKEYSは登録キー件数によってはかなり遅くなる。次に、特に重いKEYS *を同時に複数実行すると、タイムアウトするらしいので、そこを実際にやってみる。 ソースコード <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-start</artifactid></parent>…

RedisのkeysがO(N)を実際に見る

RedisのKEYSはO(n)な点に注意が必要、と各種文献に書かれている。なので実際にデータ作ってみて試してみる。 ソースコード <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <relativePath /> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceencoding></properties>

spring-batchのMapJobRepositoryFactoryBeanでメタテーブルをDBに保存せず大量にstepを実行するとスローダウン

現象 ほぼタイトルで言い切っているけど。spring-batchでメタデータ保存でDBを使わなないようインメモリに格納するMapJobRepositoryFactoryBeanを使う場合が稀に良くある。この状況下で大量のstepを含むjobを実行すると徐々に実行速度が低下していく、という…

spring-integrationでjob名渡してspring-batchを起動

spring-integration勉強中です。 spring-integrationに文字列でjob名を渡し、その先でspring-batchを起動、をつくる。https://github.com/pakmans/spring-batch-integration-example/blob/master/pom.xml を参考にした。

spring-integrationでメッセージ送信

spring-integration勉強中です。 非常にシンプルな、spring-integrationのチャネルに文字列メッセージ送信して表示するだけ、を作ってみる。 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> </project>

spring-integrationでファイル作成を検出するサンプル

spring-integration勉強中です。 というわけで https://github.com/pakmans/spring-batch-integration-example の方のコードを参考に、監視先ディレクトリにファイルが作られたらメッセージハンドラが呼び出される、というだけのコードを動かした。詳しいこ…

Elasticsearch 6.6 + Spring Data Elasticsearch 3.1.5うごかす

やったこと Elasticsearch + docker http://tech.innovation.co.jp/2018/08/09/constructing-enviroment-for-Elasticsearch-and-Kibana.html https://qiita.com/sugikeitter/items/f3b2c57bf8bbdc47a8bc 上記URLを参考にElasticsearchをdockerで動かす環境を…

spring-batchのBatchConfigurerのあたりをまなぶ

目的 たとえば、spring-batchで自前のPlatformTransactionManagerにカスタマイズしたい場合、自前のBatchConfigurerのbean定義を作成すれば有効になる。このへんの仕組みを知るために、その周辺のソースコードを読んでその動作をまなぶ。いわゆる個人の日記…

RedisのLISTに1件ずつとまとめてPUSHするときの速度差

Redisをはじめて触るので色々と試している。とりあえず基本的なパフォーマンスを見るということで、LISTに1件ずつPUSHする場合と、ある程度まとめてPUSHする場合の速度差を見る。それによってRedisを学ぶのが目的である。 ソースコード pom.xml <parent> <groupId>org.springf</groupid></parent>…

spring-bootでredisつかう

spring-bootのspring-boot-starter-data-redisを使用してRedisにアクセスする。とりあえずhello worldレベルのことをやる。 ソースコード pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.5.RELEASE</version> <relativePath /> </parent> <properties> </properties>

spring-bootのspring-data-jpaでJTAにAtomikosを使用する

spring-bootでspring-data-jpaを使う場合JTAはHIkariCPが特に何も設定しなくても使われる。通常はこれで何ら問題は無いが以下ではJTAをAtomikosに変更するやり方のメモ。 pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> </parent> <properties> <java.version>10.0</java.version></properties>

spring bootとthymeleafでfragmentsを使用してajaxをする

準備 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> </parent> <properties> <java.version>10.0</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> </dependencies>

Spring BootでSpring Securityをredisでうごかす

Spring Securityのセッション保存先をメモリからredisに変更する。 やること redisのインストール 他サイトを見て適当なマシンにredisをインストールしておく。 依存性の追加 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent>