kagamihogeの日記

kagamihogeの日記です。

Java

Spring Boot + Apache Kafkaのチュートリアルレベルの事をやる

Spring BootからApache Kafkaにpublish/subscribeする。 環境 windows 10 docker for windows(wsl2) dockerでkafka起動 qiita.com 上記を参考に構築する。本エントリで関係する書き換え箇所は以下の通り。 KAFKA_ADVERTISED_HOST_NAME - ホストのローカルア…

spring-batchでJDBCのキーブレイク

背景 Javaでキーブレイク*1を意識することはあまり無い。JPAならOneToManyで自動的にコレクションにマッピングされるし、JSONやXMLでも同様である。 今回、spring-batchでO/Rをとある事情で使えずSQLを直接使用、かつ、キーブレイクが必要になった。その実現…

spring-securityでログイン画面無しの認証

spring securityで独自の認証を実装する | エンジニアっぽいことを書くブログで紹介されているようにAbstractPreAuthenticatedProcessingFilterが使える。このクラスは、javadocによると「外部の認証システムがヘッダーやcookieなどのリクエスト経由で認証情…

Spring Batch 4.2でメトリクスをPrometheus Pushgatewayにおくる

https://docs.spring.io/spring-batch/docs/current/reference/html/monitoring-and-metrics.html を試す。 Spring Batch 4.2はMicrometerベースのメトリクスを自動的に収集する。なので、プロパティでそのメトリクスの送信設定をすれば、データがそちらに送…

Spring Cloud OpenFeignさわる

https://spring.io/projects/spring-cloud-openfeign をさわる。 FeignというRESTクライアントとspringをいい感じに連携する、という代物らしい。 使ってみる Spring Initializrでプロジェクトを作る。dependencyにopenfeignをいれる。あと、今回はレスポン…

Spring Cloud Consulさわる

Spring Cloud Consulさわる。Service DiscoveryとLoadBalancerのチュートリアルレベルのことをやる。ただし、LoadBalancerの挙動(ex. 2つ以上のserivce切り替えなど)まではやらない。 Consulとは、一言で表現するのが難しい(俺自身が良く理解してない)が…

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のJson読み込み

ソースコード plugins { id 'org.springframework.boot' version '2.2.2.RELEASE' id 'io.spring.dependency-management' version '1.0.8.RELEASE' id 'java' } dependencies { implementation 'org.springframework.boot:spring-boot-starter-batch' compil…

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.…

JEP 370: Foreign-Memory Access API (Incubator)をテキトーに訳した

https://openjdk.java.net/jeps/370 JEP 370: Foreign-Memory Access API (Incubator) Owner Maurizio Cimadamore Type Feature Scope JDK Status Proposed to Target Release 14 Component tools Discussion panama dash dev at openjdk dot java dot net C…

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

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

spring-amqpでPOJOをバイナリorJSONで送受信する

手順など pom.xml コメントアウトの箇所は後述。 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version> <relativePath /> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceencoding></properties>

Local Variable Type Inference: Style Guidelinesを読んだ

javaのvarをどう使うかについて何か良い資料無いかな、とぐぐってたら本家にあったので読んで訳した。とはいえ、ごく当たり前のことで、まとめれば、極めて狭いスコープかつ変数名は可読性を損なわないように、プラスでジェネリクスとかダイヤモンド演算子と…

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のインストール 他サイトを見て適当なマシン…

JEP 359: Records (Preview)をテキトーに訳した

http://openjdk.java.net/jeps/359 JEP 359: Records (Preview) Author Brian Goetz Owner Vicente Arturo Romero Zaldivar Type Feature Scope SE Status Candidate Component specification / language Discussion amber dash dev at openjdk dot java dot…

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>