kagamihogeの日記

kagamihogeの日記です。

2020-01-01から1年間の記事一覧

spring-kafkaでoffset指定のconsumer

spring-kafkaでoffsetを明示的に指定してconsumerを起動する。ドキュメントとしては https://docs.spring.io/spring-kafka/docs/current/reference/html/#topicpartition-initial-offset が参考になる。 plugins { id 'org.springframework.boot' version '2…

Spring Bootでjsonプロパティをenumにデシリアライズとvalidation

各種パターン まず、動作確認用の適当なmainとcontrollerを作成する。 plugins { id 'org.springframework.boot' version '2.4.1' id 'io.spring.dependency-management' version '1.0.10.RELEASE' id 'java' } group = 'com.example' version = '0.0.1-SNAP…

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…

dockerで一時的なgitリポジトリつくる

ちょっとした実験用のgitリポジトリをつくる。ローカルのディレクトリに作ってもよいけど、windowsだとsshが面倒そうだったので、dockerにした。 環境 windows 10 Docker Desktop for Windows Dockerfile FROM ubuntu:16.04 RUN apt-get update && apt-get i…

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