commit
This commit is contained in:
37
.gitignore
vendored
Normal file
37
.gitignore
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
HELP.md
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
52
build.gradle
Normal file
52
build.gradle
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'org.springframework.boot' version '2.7.9'
|
||||||
|
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.kiz'
|
||||||
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
sourceCompatibility = '17'
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
compileOnly {
|
||||||
|
extendsFrom annotationProcessor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
ext {
|
||||||
|
set('springCloudVersion', "2021.0.5")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':core-service')
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-aop'
|
||||||
|
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
||||||
|
implementation 'org.springframework.cloud:spring-cloud-starter-stream-kafka'
|
||||||
|
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
|
||||||
|
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.1.6'
|
||||||
|
compileOnly 'org.projectlombok:lombok'
|
||||||
|
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
runtimeOnly 'com.h2database:h2'
|
||||||
|
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyManagement {
|
||||||
|
imports {
|
||||||
|
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('test') {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
240
gradlew
vendored
Normal file
240
gradlew
vendored
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command;
|
||||||
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
91
gradlew.bat
vendored
Normal file
91
gradlew.bat
vendored
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
4
settings.gradle
Normal file
4
settings.gradle
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
rootProject.name = 'product-service'
|
||||||
|
|
||||||
|
include ':core-service'
|
||||||
|
project(':core-service').projectDir = new File(settingsDir, '../core-service')
|
||||||
17
src/main/java/com/kiz/app/ProductServiceApplication.java
Normal file
17
src/main/java/com/kiz/app/ProductServiceApplication.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.kiz.app;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
// @EnableJpaRepositories(basePackages = "com.kiz.adapter.out.persistence.jpa")
|
||||||
|
// @EnableJpaRepositories(basePackageClasses = StoreJpaRepository.class)
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ProductServiceApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ProductServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.kiz.app.adapter.in.web.api;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import com.kiz.app.adapter.in.web.dto.StoreCreateRequest;
|
||||||
|
import com.kiz.app.application.command.CreateStoreCommand;
|
||||||
|
import com.kiz.app.application.port.in.CreateStoreUseCase;
|
||||||
|
import com.kiz.common.WebAdapter;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/store")
|
||||||
|
@WebAdapter
|
||||||
|
public class StoreCreateController {
|
||||||
|
|
||||||
|
private final CreateStoreUseCase createStoreUseCase;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<String> save(@Valid @RequestBody final StoreCreateRequest request) {
|
||||||
|
final var id = createStoreUseCase.handle(new CreateStoreCommand(request.storeName(), request.storeLocation(), request.storeDescription()));
|
||||||
|
log.info("Created store id: {}", id);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.kiz.app.adapter.in.web.dto;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
public record StoreCreateRequest(
|
||||||
|
@NotEmpty
|
||||||
|
String storeName,
|
||||||
|
String storeLocation,
|
||||||
|
String storeDescription
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.kiz.app.adapter.out.message;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.cloud.stream.function.StreamBridge;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.kiz.event.Event;
|
||||||
|
import com.kiz.event.EventBus;
|
||||||
|
import com.kiz.event.SerializerUtils;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class KafkaEventBus implements EventBus {
|
||||||
|
|
||||||
|
private final StreamBridge streamBridge;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(List<Event> events) {
|
||||||
|
final byte[] eventsBytes = SerializerUtils.serializeToJsonBytes(events.toArray(new Event[]{}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
streamBridge.send("createStore-out-0", eventsBytes);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("(KafkaEventBus) publish get timeout", ex);
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.kiz.app.adapter.out.persistence;
|
||||||
|
|
||||||
|
import org.springframework.cloud.sleuth.annotation.NewSpan;
|
||||||
|
|
||||||
|
import com.kiz.app.application.port.out.LoadStorePort;
|
||||||
|
import com.kiz.app.application.port.out.SaveStorePort;
|
||||||
|
import com.kiz.app.application.port.out.UpdateStorePort;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.common.PersistenceAdapter;
|
||||||
|
import com.kiz.event.EventStoreDB;
|
||||||
|
|
||||||
|
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
|
||||||
|
import io.github.resilience4j.retry.annotation.Retry;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@PersistenceAdapter
|
||||||
|
public class StoreCommandAdapter implements SaveStorePort, UpdateStorePort, LoadStorePort {
|
||||||
|
|
||||||
|
private final EventStoreDB eventStoreDB;
|
||||||
|
private static final String SERVICE_NAME = "microservice";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NewSpan
|
||||||
|
@Retry(name = SERVICE_NAME)
|
||||||
|
@CircuitBreaker(name = SERVICE_NAME)
|
||||||
|
public Store load(String aggregateId) {
|
||||||
|
return eventStoreDB.load(aggregateId, Store.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NewSpan
|
||||||
|
@Retry(name = SERVICE_NAME)
|
||||||
|
@CircuitBreaker(name = SERVICE_NAME)
|
||||||
|
public String save(Store aggregate) {
|
||||||
|
eventStoreDB.save(aggregate);
|
||||||
|
log.info("(createStore) aggregate: {}", aggregate);
|
||||||
|
return aggregate.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NewSpan
|
||||||
|
@Retry(name = SERVICE_NAME)
|
||||||
|
@CircuitBreaker(name = SERVICE_NAME)
|
||||||
|
public Store updateStore(Store aggregate) {
|
||||||
|
eventStoreDB.save(aggregate);
|
||||||
|
log.info("(updateStore) aggregate: {}", aggregate);
|
||||||
|
return aggregate;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.kiz.app.adapter.out.persistence;
|
||||||
|
|
||||||
|
import com.kiz.app.adapter.out.persistence.jpa.StoreJpaRepository;
|
||||||
|
import com.kiz.app.application.port.out.GetStoreByIdPort;
|
||||||
|
import com.kiz.app.application.query.GetStoreByIdQuery;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.common.PersistenceAdapter;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@PersistenceAdapter
|
||||||
|
public class StoreQueryAdapter implements GetStoreByIdPort {
|
||||||
|
|
||||||
|
private final StoreJpaRepository storeJpaRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Store getStoreById(GetStoreByIdQuery query) {
|
||||||
|
log.info("(GetStoreByIdQuery) query: {}", query);
|
||||||
|
storeJpaRepository.findByStoreId(query.id());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
package com.kiz.app.adapter.out.persistence.jdbc;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.cloud.sleuth.annotation.NewSpan;
|
||||||
|
import org.springframework.cloud.sleuth.annotation.SpanTag;
|
||||||
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.kiz.event.AggregateRoot;
|
||||||
|
import com.kiz.event.Event;
|
||||||
|
import com.kiz.event.EventBus;
|
||||||
|
import com.kiz.event.EventSourcingUtils;
|
||||||
|
import com.kiz.event.EventStoreDB;
|
||||||
|
import com.kiz.event.Snapshot;
|
||||||
|
import com.kiz.event.exceptions.AggregateNotFoundException;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import static com.kiz.event.Constants.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Repository
|
||||||
|
public class JdbcEventStore implements EventStoreDB {
|
||||||
|
|
||||||
|
public static final int SNAPSHOT_FREQUENCY = 3;
|
||||||
|
private static final String SAVE_EVENTS_QUERY = "INSERT INTO events (aggregate_id, aggregate_type, event_type, data, metadata, version, timestamp) values (:aggregate_id, :aggregate_type, :event_type, :data, :metadata, :version, now())";
|
||||||
|
private static final String LOAD_EVENTS_QUERY = "SELECT event_id ,aggregate_id, aggregate_type, event_type, data, metadata, version, timestamp FROM events e WHERE e.aggregate_id = :aggregate_id AND e.version > :version ORDER BY e.version ASC";
|
||||||
|
private static final String SAVE_SNAPSHOT_QUERY = "INSERT INTO snapshots (aggregate_id, aggregate_type, data, metadata, version, timestamp) VALUES (:aggregate_id, :aggregate_type, :data, :metadata, :version, now()) ON CONFLICT (aggregate_id) DO UPDATE SET data = :data, version = :version, timestamp = now()";
|
||||||
|
private static final String HANDLE_CONCURRENCY_QUERY = "SELECT aggregate_id FROM events e WHERE e.aggregate_id = :aggregate_id LIMIT 1 FOR UPDATE";
|
||||||
|
private static final String LOAD_SNAPSHOT_QUERY = "SELECT aggregate_id, aggregate_type, data, metadata, version, timestamp FROM snapshots s WHERE s.aggregate_id = :aggregate_id";
|
||||||
|
private static final String EXISTS_QUERY = "SELECT aggregate_id FROM events WHERE e e.aggregate_id = :aggregate_id";
|
||||||
|
|
||||||
|
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||||
|
private final EventBus eventBus;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
@NewSpan
|
||||||
|
public <T extends AggregateRoot> void save(@SpanTag("aggregate") T aggregate) {
|
||||||
|
final List<Event> aggregateEvents = new ArrayList<>(aggregate.getChanges());
|
||||||
|
|
||||||
|
if (aggregate.getVersion() > 1) {
|
||||||
|
this.handleConcurrency(aggregate.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.saveEvents(aggregate.getChanges());
|
||||||
|
if (aggregate.getVersion() % SNAPSHOT_FREQUENCY == 0) {
|
||||||
|
this.saveSnapshot(aggregate);
|
||||||
|
}
|
||||||
|
|
||||||
|
eventBus.publish(aggregateEvents);
|
||||||
|
|
||||||
|
log.info("(save) saved aggregate: {}", aggregate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
@NewSpan
|
||||||
|
public <T extends AggregateRoot> T load(@SpanTag("aggregateId") String aggregateId, @SpanTag("aggregateType") Class<T> aggregateType) {
|
||||||
|
|
||||||
|
final Optional<Snapshot> snapshot = this.loadSnapshot(aggregateId);
|
||||||
|
|
||||||
|
final var aggregate = this.getSnapshotFromClass(snapshot, aggregateId, aggregateType);
|
||||||
|
|
||||||
|
final List<Event> events = this.loadEvents(aggregateId, aggregate.getVersion());
|
||||||
|
events.forEach(event -> {
|
||||||
|
aggregate.raiseEvent(event);
|
||||||
|
log.info("raise event version: {}", event.getVersion());
|
||||||
|
});
|
||||||
|
|
||||||
|
if (aggregate.getVersion() == 0) throw new AggregateNotFoundException(aggregateId);
|
||||||
|
|
||||||
|
log.info("(load) loaded aggregate: {}", aggregate);
|
||||||
|
return aggregate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NewSpan
|
||||||
|
public void saveEvents(@SpanTag("events") List<Event> events) {
|
||||||
|
if (events.isEmpty()) return;
|
||||||
|
|
||||||
|
final List<Event> changes = new ArrayList<>(events);
|
||||||
|
if (changes.size() > 1) {
|
||||||
|
this.eventsBatchInsert(changes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Event event = changes.get(0);
|
||||||
|
int result = jdbcTemplate.update(SAVE_EVENTS_QUERY, mapFromEvent(event));
|
||||||
|
log.info("(saveEvents) saved result: {}, event: {}", result, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Serializable> mapFromEvent(Event event) {
|
||||||
|
return Map.of(
|
||||||
|
AGGREGATE_ID, event.getAggregateId(),
|
||||||
|
AGGREGATE_TYPE, event.getAggregateType(),
|
||||||
|
EVENT_TYPE, event.getEventType(),
|
||||||
|
DATA, Objects.isNull(event.getData()) ? new byte[]{} : event.getData(),
|
||||||
|
METADATA, Objects.isNull(event.getMetaData()) ? new byte[]{} : event.getMetaData(),
|
||||||
|
VERSION, event.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void eventsBatchInsert(@SpanTag("events") List<Event> events) {
|
||||||
|
final var args = events.stream().map(this::mapFromEvent).toList();
|
||||||
|
final Map<String, ?>[] maps = args.toArray(new Map[0]);
|
||||||
|
|
||||||
|
int[] ints = jdbcTemplate.batchUpdate(SAVE_EVENTS_QUERY, maps);
|
||||||
|
log.info("(saveEvents) BATCH saved result: {}, event: {}", ints);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NewSpan
|
||||||
|
public List<Event> loadEvents(@SpanTag("aggregateId") String aggregateId, @SpanTag("version") long version) {
|
||||||
|
return jdbcTemplate.query(LOAD_EVENTS_QUERY, Map.of(AGGREGATE_ID, aggregateId, VERSION, version),
|
||||||
|
(rs, rowNum) -> Event.builder()
|
||||||
|
.aggregateId(rs.getString(AGGREGATE_ID))
|
||||||
|
.aggregateType(rs.getString(AGGREGATE_TYPE))
|
||||||
|
.eventType(rs.getString(EVENT_TYPE))
|
||||||
|
.data(rs.getBytes(DATA))
|
||||||
|
.metaData(rs.getBytes(METADATA))
|
||||||
|
.version(rs.getLong(VERSION))
|
||||||
|
.timeStamp(rs.getTimestamp(TIMESTAMP).toLocalDateTime())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
private <T extends AggregateRoot> void saveSnapshot(@SpanTag("aggregate") T aggregate) {
|
||||||
|
aggregate.toSnapshot();
|
||||||
|
final var snapshot = EventSourcingUtils.snapshotFromAggregate(aggregate);
|
||||||
|
|
||||||
|
int updateResult = jdbcTemplate.update(SAVE_SNAPSHOT_QUERY,
|
||||||
|
Map.of(AGGREGATE_ID, snapshot.getAggregateId(),
|
||||||
|
AGGREGATE_TYPE, snapshot.getAggregateType(),
|
||||||
|
DATA, Objects.isNull(snapshot.getData()) ? new byte[]{} : snapshot.getData(),
|
||||||
|
METADATA, Objects.isNull(snapshot.getMetaData()) ? new byte[]{} : snapshot.getMetaData(),
|
||||||
|
VERSION, snapshot.getVersion()));
|
||||||
|
|
||||||
|
log.info("(saveSnapshot) updateResult: {}", updateResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
private void handleConcurrency(@SpanTag("aggregateId") String aggregateId) {
|
||||||
|
try {
|
||||||
|
String aggregateID = jdbcTemplate.queryForObject(HANDLE_CONCURRENCY_QUERY, Map.of(AGGREGATE_ID, aggregateId), String.class);
|
||||||
|
log.info("(handleConcurrency) aggregateID for lock: {}", aggregateID);
|
||||||
|
} catch (EmptyResultDataAccessException e) {
|
||||||
|
log.info("(handleConcurrency) EmptyResultDataAccessException: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
log.info("(handleConcurrency) aggregateID for lock: {}", aggregateId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
private Optional<Snapshot> loadSnapshot(@SpanTag("aggregateId") String aggregateId) {
|
||||||
|
return jdbcTemplate.query(LOAD_SNAPSHOT_QUERY, Map.of(AGGREGATE_ID, aggregateId), (rs, rowNum) -> Snapshot.builder()
|
||||||
|
.aggregateId(rs.getString(AGGREGATE_ID))
|
||||||
|
.aggregateType(rs.getString(AGGREGATE_TYPE))
|
||||||
|
.data(rs.getBytes(DATA))
|
||||||
|
.metaData(rs.getBytes(METADATA))
|
||||||
|
.version(rs.getLong(VERSION))
|
||||||
|
.timeStamp(rs.getTimestamp(TIMESTAMP).toLocalDateTime())
|
||||||
|
.build()).stream().findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
private <T extends AggregateRoot> T getAggregate(@SpanTag("aggregateId") final String aggregateId, @SpanTag("aggregateType") final Class<T> aggregateType) {
|
||||||
|
try {
|
||||||
|
return aggregateType.getConstructor(String.class).newInstance(aggregateId);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
private <T extends AggregateRoot> T getSnapshotFromClass(@SpanTag("snapshot") Optional<Snapshot> snapshot, @SpanTag("aggregateId") String aggregateId, @SpanTag("aggregateType") Class<T> aggregateType) {
|
||||||
|
if (snapshot.isEmpty()) {
|
||||||
|
final var defaultSnapshot = EventSourcingUtils.snapshotFromAggregate(getAggregate(aggregateId, aggregateType));
|
||||||
|
return EventSourcingUtils.aggregateFromSnapshot(defaultSnapshot, aggregateType);
|
||||||
|
}
|
||||||
|
return EventSourcingUtils.aggregateFromSnapshot(snapshot.get(), aggregateType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NewSpan
|
||||||
|
public Boolean exists(@SpanTag("aggregateId") String aggregateId) {
|
||||||
|
try {
|
||||||
|
final var id = jdbcTemplate.queryForObject(EXISTS_QUERY, Map.of(AGGREGATE_ID, aggregateId), String.class);
|
||||||
|
log.info("aggregate exists id: {}", id);
|
||||||
|
return true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!(ex instanceof EmptyResultDataAccessException)) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.kiz.app.adapter.out.persistence.jpa;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
|
@Entity
|
||||||
|
@Table(name = "store")
|
||||||
|
public class StoreEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "store_id")
|
||||||
|
@Getter private Long storeId;
|
||||||
|
@Column(name = "aggregate_id", length = 36, nullable = false, unique = true)
|
||||||
|
@Getter private String aggregateId;
|
||||||
|
@Column(name = "store_name", length = 50, nullable = false)
|
||||||
|
@Getter private String storeName;
|
||||||
|
@Column(name = "store_location", length = 50, nullable = false)
|
||||||
|
@Getter private String storeLocation;
|
||||||
|
@Column(name = "store_description", length = 1000)
|
||||||
|
@Getter private String storeDescription;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public StoreEntity(String aggregateId, String storeName, String storeLocation, String storeDescription) {
|
||||||
|
this.aggregateId = aggregateId;
|
||||||
|
this.storeName = storeName;
|
||||||
|
this.storeLocation = storeLocation;
|
||||||
|
this.storeDescription = storeDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.kiz.app.adapter.out.persistence.jpa;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface StoreJpaRepository extends JpaRepository<StoreEntity, Long> {
|
||||||
|
|
||||||
|
Optional<StoreEntity> findByStoreId(Long storeId);
|
||||||
|
|
||||||
|
Optional<StoreEntity> findByAggregateId(String aggregateId);
|
||||||
|
|
||||||
|
void deleteByAggregateId(String aggregateId);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package com.kiz.app.adapter.out.persistence.projection;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.springframework.cloud.sleuth.annotation.NewSpan;
|
||||||
|
import org.springframework.cloud.sleuth.annotation.SpanTag;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.kiz.app.adapter.out.persistence.jpa.StoreEntity;
|
||||||
|
import com.kiz.app.adapter.out.persistence.jpa.StoreJpaRepository;
|
||||||
|
import com.kiz.app.domain.event.StoreCreateEvent;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.event.Event;
|
||||||
|
import com.kiz.event.EventStoreDB;
|
||||||
|
import com.kiz.event.Projection;
|
||||||
|
import com.kiz.event.SerializerUtils;
|
||||||
|
|
||||||
|
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
|
||||||
|
import io.github.resilience4j.retry.annotation.Retry;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class StoreJpaProjection implements Projection {
|
||||||
|
|
||||||
|
private final StoreJpaRepository storeJpaRepository;
|
||||||
|
private final EventStoreDB eventStoreDB;
|
||||||
|
private static final String SERVICE_NAME = "microservice";
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
private Consumer<byte[]> createStore() {
|
||||||
|
return (data) -> {
|
||||||
|
log.info("createStore 이벤트 수신");
|
||||||
|
try {
|
||||||
|
final Event[] events = SerializerUtils.deserializeEventsFromJsonBytes(data);
|
||||||
|
this.processEvents(Arrays.stream(events).toList());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("(CreateStoreProjection)", ex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
private void processEvents(@SpanTag("events") List<Event> events) {
|
||||||
|
if (events.isEmpty()) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
events.forEach(this::when);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
storeJpaRepository.deleteByAggregateId(events.get(0).getAggregateId());
|
||||||
|
final var aggregate = eventStoreDB.load(events.get(0).getAggregateId(), Store.class);
|
||||||
|
final var result = storeJpaRepository.save(
|
||||||
|
StoreEntity.builder()
|
||||||
|
.aggregateId(aggregate.getId())
|
||||||
|
.storeName(aggregate.getStoreName())
|
||||||
|
.storeLocation(aggregate.getStoreLocation())
|
||||||
|
.storeDescription(aggregate.getStoreDescription())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
log.info("(processEvents) saved entity: {}", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
@Retry(name = SERVICE_NAME)
|
||||||
|
@CircuitBreaker(name = SERVICE_NAME)
|
||||||
|
@Override
|
||||||
|
public void when(@SpanTag("event") Event event) {
|
||||||
|
final var aggregateId = event.getAggregateId();
|
||||||
|
log.info("(when) >>>>> aggregateId: {}", aggregateId);
|
||||||
|
|
||||||
|
switch (event.getEventType()) {
|
||||||
|
case StoreCreateEvent.STORE_CREATED_V1 ->
|
||||||
|
handle(SerializerUtils.deserializeFromJsonBytes(event.getData(), StoreCreateEvent.class));
|
||||||
|
default -> log.error("unknown event type: {}", event.getEventType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NewSpan
|
||||||
|
private void handle(@SpanTag("event") StoreCreateEvent event) {
|
||||||
|
log.info("(when) StoreCreateEvent: {}, aggregateID: {}", event, event.getAggregateId());
|
||||||
|
|
||||||
|
final var entity = StoreEntity.builder()
|
||||||
|
.aggregateId(event.getAggregateId())
|
||||||
|
.storeName(event.getStoreName())
|
||||||
|
.storeLocation(event.getStoreLocation())
|
||||||
|
.storeDescription(event.getStoreDescription())
|
||||||
|
.build();
|
||||||
|
final var insert = storeJpaRepository.save(entity);
|
||||||
|
|
||||||
|
log.info("(StoreCreateEvent) insert: {}", insert);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.kiz.app.application.command;
|
||||||
|
|
||||||
|
public record CreateStoreCommand(String storeName, String storeLocation, String storeDescription) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.kiz.app.application.command;
|
||||||
|
|
||||||
|
public record UpdateStoreCommand(String aggregateId, String storeName, String storeLocation, String storeDescription) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.kiz.app.application.port.in;
|
||||||
|
|
||||||
|
import com.kiz.app.application.command.CreateStoreCommand;
|
||||||
|
|
||||||
|
public interface CreateStoreUseCase {
|
||||||
|
String handle(CreateStoreCommand command);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.kiz.app.application.port.in;
|
||||||
|
|
||||||
|
public interface FindAllStoreUseCase {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.kiz.app.application.port.in;
|
||||||
|
|
||||||
|
public interface FindSearchStoreUseCase {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.kiz.app.application.port.in;
|
||||||
|
|
||||||
|
import com.kiz.app.application.query.GetStoreByIdQuery;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
|
||||||
|
public interface GetStoreByIdUseCase {
|
||||||
|
Store handle(GetStoreByIdQuery query);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.kiz.app.application.port.in;
|
||||||
|
|
||||||
|
import com.kiz.app.application.command.UpdateStoreCommand;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
|
||||||
|
public interface UpdateStoreUseCase {
|
||||||
|
Store handle(UpdateStoreCommand command);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.kiz.app.application.port.out;
|
||||||
|
|
||||||
|
import com.kiz.app.application.query.GetStoreByIdQuery;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
|
||||||
|
public interface GetStoreByIdPort {
|
||||||
|
Store getStoreById(GetStoreByIdQuery query);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.kiz.app.application.port.out;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
|
||||||
|
public interface LoadStorePort {
|
||||||
|
Store load(String aggregateId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.kiz.app.application.port.out;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
|
||||||
|
public interface SaveStorePort {
|
||||||
|
String save(Store aggregate);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.kiz.app.application.port.out;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
|
||||||
|
public interface UpdateStorePort {
|
||||||
|
Store updateStore(Store aggregate);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.kiz.app.application.query;
|
||||||
|
|
||||||
|
public record GetStoreByIdQuery(Long id) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.kiz.app.application.service;
|
||||||
|
|
||||||
|
import com.kiz.app.application.command.CreateStoreCommand;
|
||||||
|
import com.kiz.app.application.port.in.CreateStoreUseCase;
|
||||||
|
import com.kiz.app.application.port.out.SaveStorePort;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.common.UseCase;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@UseCase
|
||||||
|
public class CreateStoreService implements CreateStoreUseCase {
|
||||||
|
|
||||||
|
private final SaveStorePort saveStorePort;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String handle(CreateStoreCommand command) {
|
||||||
|
final var aggregate = new Store(new Store.StoreId().getValue());
|
||||||
|
aggregate.createStore(command.storeName() , command.storeLocation(), command.storeDescription());
|
||||||
|
return saveStorePort.save(aggregate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.kiz.app.application.service;
|
||||||
|
|
||||||
|
import com.kiz.app.application.port.in.GetStoreByIdUseCase;
|
||||||
|
import com.kiz.app.application.query.GetStoreByIdQuery;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.common.UseCase;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@UseCase
|
||||||
|
public class GetStoreByIdService implements GetStoreByIdUseCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Store handle(GetStoreByIdQuery query) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.kiz.app.application.service;
|
||||||
|
|
||||||
|
import com.kiz.app.application.command.UpdateStoreCommand;
|
||||||
|
import com.kiz.app.application.port.in.UpdateStoreUseCase;
|
||||||
|
import com.kiz.app.application.port.out.LoadStorePort;
|
||||||
|
import com.kiz.app.application.port.out.UpdateStorePort;
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.common.UseCase;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@UseCase
|
||||||
|
public class UpdateStoreService implements UpdateStoreUseCase {
|
||||||
|
|
||||||
|
private final LoadStorePort storeLoadPort;
|
||||||
|
private final UpdateStorePort storeUpdatePort;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Store handle(UpdateStoreCommand command) {
|
||||||
|
final var aggregate = storeLoadPort.load(command.aggregateId());
|
||||||
|
aggregate.updateStore(command.storeName(), command.storeLocation(), command.storeDescription());
|
||||||
|
return storeUpdatePort.updateStore(aggregate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.kiz.app.domain.event;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.event.BaseEvent;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class CategoryCreateEvent extends BaseEvent {
|
||||||
|
|
||||||
|
public static final String CATEGORY_CREATED_V1 = "CATEGORY_CREATED_V1";
|
||||||
|
public static final String AGGREGATE_TYPE = Store.AGGREGATE_TYPE;
|
||||||
|
|
||||||
|
@Getter private String storeId;
|
||||||
|
@Getter private int categoryLevel;
|
||||||
|
@Getter private Long categoryParentId;
|
||||||
|
@Getter private String categoryName;
|
||||||
|
@Getter private String categoryDescription;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public CategoryCreateEvent(String aggregateId, String storeId, int categoryLevel, Long categoryParentId, String categoryName, String categoryDescription) {
|
||||||
|
super(aggregateId);
|
||||||
|
this.storeId = storeId;
|
||||||
|
this.categoryLevel = categoryLevel;
|
||||||
|
this.categoryParentId = categoryParentId;
|
||||||
|
this.categoryName = categoryName;
|
||||||
|
this.categoryDescription = categoryDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
26
src/main/java/com/kiz/app/domain/event/StoreCreateEvent.java
Normal file
26
src/main/java/com/kiz/app/domain/event/StoreCreateEvent.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package com.kiz.app.domain.event;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.event.BaseEvent;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class StoreCreateEvent extends BaseEvent {
|
||||||
|
|
||||||
|
public static final String STORE_CREATED_V1 = "STORE_CREATED_V1";
|
||||||
|
public static final String AGGREGATE_TYPE = Store.AGGREGATE_TYPE;
|
||||||
|
|
||||||
|
@Getter private String storeName;
|
||||||
|
@Getter private String storeLocation;
|
||||||
|
@Getter private String storeDescription;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public StoreCreateEvent(String aggregateId, String storeName, String storeLocation, String storeDescription) {
|
||||||
|
super(aggregateId);
|
||||||
|
this.storeName = storeName;
|
||||||
|
this.storeLocation = storeLocation;
|
||||||
|
this.storeDescription = storeDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
26
src/main/java/com/kiz/app/domain/event/StoreUpdateEvent.java
Normal file
26
src/main/java/com/kiz/app/domain/event/StoreUpdateEvent.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package com.kiz.app.domain.event;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
import com.kiz.event.BaseEvent;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class StoreUpdateEvent extends BaseEvent {
|
||||||
|
|
||||||
|
public static final String STORE_UPDATE_V1 = "STORE_UPDATE_V1";
|
||||||
|
public static final String AGGREGATE_TYPE = Store.AGGREGATE_TYPE;
|
||||||
|
|
||||||
|
@Getter private String storeName;
|
||||||
|
@Getter private String storeLocation;
|
||||||
|
@Getter private String storeDescription;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public StoreUpdateEvent(String aggregateId, String storeName, String storeLocation, String storeDescription) {
|
||||||
|
super(aggregateId);
|
||||||
|
this.storeName = storeName;
|
||||||
|
this.storeLocation = storeLocation;
|
||||||
|
this.storeDescription = storeDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.kiz.app.domain.exception;
|
||||||
|
|
||||||
|
public class InvalidCategoryNameException extends RuntimeException {
|
||||||
|
|
||||||
|
public InvalidCategoryNameException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidCategoryNameException(String categoryName) {
|
||||||
|
super("invalid categoryName: " + categoryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
src/main/java/com/kiz/app/domain/model/Category.java
Normal file
22
src/main/java/com/kiz/app/domain/model/Category.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package com.kiz.app.domain.model;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class Category {
|
||||||
|
|
||||||
|
public static class CategoryId {
|
||||||
|
@Getter private final String value;
|
||||||
|
public CategoryId() {
|
||||||
|
this.value = UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter private int categoryLevel;
|
||||||
|
@Getter private Long categoryParentId;
|
||||||
|
@Getter private String categoryName;
|
||||||
|
@Getter private String categoryDescription;
|
||||||
|
@Getter private Store store;
|
||||||
|
|
||||||
|
}
|
||||||
5
src/main/java/com/kiz/app/domain/model/Product.java
Normal file
5
src/main/java/com/kiz/app/domain/model/Product.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package com.kiz.app.domain.model;
|
||||||
|
|
||||||
|
public class Product {
|
||||||
|
|
||||||
|
}
|
||||||
5
src/main/java/com/kiz/app/domain/model/ProductImage.java
Normal file
5
src/main/java/com/kiz/app/domain/model/ProductImage.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package com.kiz.app.domain.model;
|
||||||
|
|
||||||
|
public class ProductImage {
|
||||||
|
|
||||||
|
}
|
||||||
84
src/main/java/com/kiz/app/domain/model/Store.java
Normal file
84
src/main/java/com/kiz/app/domain/model/Store.java
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package com.kiz.app.domain.model;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.event.StoreCreateEvent;
|
||||||
|
import com.kiz.app.domain.event.StoreUpdateEvent;
|
||||||
|
import com.kiz.event.AggregateRoot;
|
||||||
|
import com.kiz.event.Event;
|
||||||
|
import com.kiz.event.SerializerUtils;
|
||||||
|
import com.kiz.event.exceptions.InvalidEventTypeException;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Store extends AggregateRoot {
|
||||||
|
|
||||||
|
public static final String AGGREGATE_TYPE = "StoreAggregate";
|
||||||
|
|
||||||
|
public Store(String id) {
|
||||||
|
super(id, AGGREGATE_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class StoreId {
|
||||||
|
@Getter private final String value;
|
||||||
|
public StoreId() {
|
||||||
|
this.value = UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter private String storeName;
|
||||||
|
@Getter private String storeLocation;
|
||||||
|
@Getter private String storeDescription;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void when(Event event) {
|
||||||
|
switch (event.getEventType()) {
|
||||||
|
case StoreCreateEvent.STORE_CREATED_V1 ->
|
||||||
|
handle(SerializerUtils.deserializeFromJsonBytes(event.getData(), StoreCreateEvent.class));
|
||||||
|
case StoreUpdateEvent.STORE_UPDATE_V1 ->
|
||||||
|
handle(SerializerUtils.deserializeFromJsonBytes(event.getData(), StoreUpdateEvent.class));
|
||||||
|
default -> throw new InvalidEventTypeException(event.getEventType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handle(final StoreCreateEvent event) {
|
||||||
|
this.storeName = event.getStoreName();
|
||||||
|
this.storeLocation = event.getStoreLocation();
|
||||||
|
this.storeDescription = event.getStoreDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handle(final StoreUpdateEvent event) {
|
||||||
|
this.storeName = event.getStoreName();
|
||||||
|
this.storeLocation = event.getStoreLocation();
|
||||||
|
this.storeDescription = event.getStoreDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createStore(String storeName, String storeLocation, String storeDescription) {
|
||||||
|
final var data = StoreCreateEvent.builder()
|
||||||
|
.aggregateId(id)
|
||||||
|
.storeName(storeName)
|
||||||
|
.storeLocation(storeLocation)
|
||||||
|
.storeDescription(storeDescription)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
final byte[] dataBytes = SerializerUtils.serializeToJsonBytes(data);
|
||||||
|
final var event = this.createEvent(StoreCreateEvent.STORE_CREATED_V1, dataBytes, null);
|
||||||
|
this.apply(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateStore(String storeName, String storeLocation, String storeDescription) {
|
||||||
|
final var data = StoreUpdateEvent.builder()
|
||||||
|
.aggregateId(id)
|
||||||
|
.storeName(storeName)
|
||||||
|
.storeLocation(storeLocation)
|
||||||
|
.storeDescription(storeDescription)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
final byte[] dataBytes = SerializerUtils.serializeToJsonBytes(data);
|
||||||
|
final var event = this.createEvent(StoreUpdateEvent.STORE_UPDATE_V1, dataBytes, null);
|
||||||
|
this.apply(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.kiz.app.domain.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.kiz.app.domain.model.Store;
|
||||||
|
|
||||||
|
public interface StoreRepository {
|
||||||
|
Store save(Store order);
|
||||||
|
List<Store> findAll();
|
||||||
|
Store findById(Long id);
|
||||||
|
void delete(Store order);
|
||||||
|
}
|
||||||
55
src/main/resources/application.yaml
Normal file
55
src/main/resources/application.yaml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
server:
|
||||||
|
port: 0
|
||||||
|
|
||||||
|
spring:
|
||||||
|
config:
|
||||||
|
activate:
|
||||||
|
on-profile: local
|
||||||
|
datasource:
|
||||||
|
driver-class-name: org.mariadb.jdbc.Driver
|
||||||
|
url: jdbc:mariadb://mindol.synology.me:3307/kiz_space
|
||||||
|
username: mindolangel
|
||||||
|
password: $awlswn1318A
|
||||||
|
jpa:
|
||||||
|
database: mysql
|
||||||
|
open-in-view: false
|
||||||
|
generate-ddl: true
|
||||||
|
show-sql: true
|
||||||
|
hibernate: # hibernate 사용 설정
|
||||||
|
ddl-auto: update
|
||||||
|
properties: # property 사용 설정
|
||||||
|
hibernate: # hibernate property 설정
|
||||||
|
ogm:
|
||||||
|
datastore:
|
||||||
|
create:
|
||||||
|
database: true
|
||||||
|
format-sql: true
|
||||||
|
cloud:
|
||||||
|
function:
|
||||||
|
definition: createStore
|
||||||
|
stream:
|
||||||
|
bindings:
|
||||||
|
createStore-out-0:
|
||||||
|
destination: store-create-topic
|
||||||
|
group: store-group
|
||||||
|
kafka:
|
||||||
|
binder:
|
||||||
|
brokers: mindol.synology.me:19092
|
||||||
|
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: "*"
|
||||||
|
endpoint:
|
||||||
|
shutdown:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com:
|
||||||
|
kiz: DEBUG
|
||||||
|
org:
|
||||||
|
hibernate:
|
||||||
|
SQL: debug
|
||||||
|
type: trace
|
||||||
27
src/main/resources/bootstrap.yaml
Normal file
27
src/main/resources/bootstrap.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: product-service # 서비스 ID (컨피그 클라이언트가 어떤 서비스를 조회하는지 매핑)
|
||||||
|
profiles:
|
||||||
|
active: local # 서비스가 실행할 기본 프로파일
|
||||||
|
# cloud:
|
||||||
|
# config:
|
||||||
|
# uri: http://localhost:8889 # 컨피그 서버 위치
|
||||||
|
# name: user
|
||||||
|
# profile: default
|
||||||
|
|
||||||
|
eureka:
|
||||||
|
instance:
|
||||||
|
hostname: mindol.synology.me
|
||||||
|
instance-id: ${spring.cloud.client.hostname}:${spring.application.instance_id:${random.value}}
|
||||||
|
lease-renewal-interval-in-seconds: 30 # 유레카 서버로 설정된 시간(second)마다 하트비트 전송 (디폴트 30초)
|
||||||
|
# 디스커버리는 서비스 등록 해제 하기 전에 마지막 하트비트에서부터 설정된 시간(second) 동안 하트비트가 수신되지 않으면
|
||||||
|
# 서비스 등록 해제 (디폴트 90초)
|
||||||
|
lease-expiration-duration-in-seconds: 90
|
||||||
|
prefer-ip-address: true # 서비스의 호스트 이름이 아닌 IP 주소를 유레카 서버에 등록하도록 지정 (디폴트 false)
|
||||||
|
client:
|
||||||
|
register-with-eureka: true # 레지스트리에 자신을 등록할지에 대한 여부 (디폴트 true)
|
||||||
|
fetch-registry: true # 레지스트리에 있는 정보를 가져올지에 대한 여부 (디폴트 true)
|
||||||
|
registry-fetch-interval-seconds: 30 # 서비스 목록을 설정한 시간마다 캐싱 (디폴트 30초)
|
||||||
|
disable-delta: true # 캐싱 시 변경된 부분만 업데이트할 지 여부 (디폴트 false)
|
||||||
|
serviceUrl:
|
||||||
|
defaultZone: http://${eureka.instance.hostname}:8761/eureka/
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.kiz.app;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class ProductServiceApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user