├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── LICENSE
├── README.md
├── agents
└── opentelemetry-javaagent.jar
├── assets
├── kibana-1.png
├── zipkin-1_0.png
└── zipkin-1_1.png
├── containerized-accounts
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── k8n
│ ├── deployment.yml
│ └── service.yml
├── mvnw
├── mvnw.cmd
├── opentelemetry-javaagent.jar
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── tanerdiler
│ │ │ └── microservice
│ │ │ └── accounts
│ │ │ ├── ContainerizedAccountsApplication.java
│ │ │ ├── config
│ │ │ └── Config.java
│ │ │ ├── model
│ │ │ └── Account.java
│ │ │ ├── repository
│ │ │ └── AccountRepository.java
│ │ │ └── resource
│ │ │ └── AccountResource.java
│ └── resources
│ │ ├── application.yml
│ │ ├── banner.txt
│ │ └── logback-spring.xml
│ └── test
│ └── java
│ └── com
│ └── tanerdiler
│ └── microservice
│ └── accounts
│ └── ContainerizedAccountsApplicationTests.java
├── containerized-discovery
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── k8n
│ ├── deployment.yml
│ └── service.yml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── tanerdiler
│ │ └── microservice
│ │ └── discovery
│ │ └── ContainerizedDiscoveryApplication.java
│ └── resources
│ ├── application.yml
│ ├── banner.txt
│ └── logback-spring.xml
├── containerized-gateway
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── k8n
│ ├── deployment.yml
│ └── service.yml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── tanerdiler
│ │ └── microservice
│ │ └── gateway
│ │ └── ContainerizedGatewayApplication.java
│ └── resources
│ ├── application.yml
│ ├── banner.txt
│ └── logback-spring.xml
├── containerized-grafana
└── etc
│ ├── dashboards.yaml
│ ├── dashboards
│ └── spring-boot-observability.json
│ └── grafana
│ └── datasource.yml
├── containerized-logstash
├── config
│ └── logstash.yml
└── pipeline
│ └── logstash.conf
├── containerized-main
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── k8n
│ ├── deployment.yml
│ └── service.yml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── tanerdiler
│ │ │ └── microservice
│ │ │ └── main
│ │ │ ├── ContainerizedMainApplication.java
│ │ │ ├── config
│ │ │ └── Config.java
│ │ │ ├── dto
│ │ │ └── OrderDTO.java
│ │ │ ├── model
│ │ │ ├── Account.java
│ │ │ ├── Order.java
│ │ │ └── Product.java
│ │ │ ├── repository
│ │ │ ├── AccountServiceClient.java
│ │ │ ├── OrderServiceClient.java
│ │ │ └── ProductServiceClient.java
│ │ │ └── resource
│ │ │ └── BackofficeController.java
│ └── resources
│ │ ├── application.yml
│ │ ├── banner.txt
│ │ └── logback-spring.xml
│ └── test
│ └── java
│ └── com
│ └── tanerdiler
│ └── microservice
│ └── main
│ └── ContainerizedAccountsApplicationTests.java
├── containerized-orders
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── k8n
│ ├── deployment.yml
│ └── service.yml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── tanerdiler
│ │ │ └── microservice
│ │ │ └── order
│ │ │ ├── ContainerizedOrdersApplication.java
│ │ │ ├── config
│ │ │ └── Config.java
│ │ │ ├── model
│ │ │ └── Order.java
│ │ │ ├── repository
│ │ │ └── OrderRepository.java
│ │ │ └── resource
│ │ │ └── OrderResource.java
│ └── resources
│ │ ├── application.yml
│ │ ├── banner.txt
│ │ └── logback-spring.xml
│ └── test
│ └── java
│ └── com
│ └── tanerdiler
│ └── microservice
│ └── order
│ └── ContainerizedOrdersApplicationTests.java
├── containerized-products
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── k8n
│ ├── deployment.yml
│ └── service.yml
├── mvnw
├── mvnw.cmd
├── opentelemetry-javaagent.jar
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── tanerdiler
│ │ │ └── microservice
│ │ │ └── product
│ │ │ ├── ContainerizedProductsApplication.java
│ │ │ ├── config
│ │ │ └── Config.java
│ │ │ ├── model
│ │ │ └── Product.java
│ │ │ ├── repository
│ │ │ └── ProductRepository.java
│ │ │ └── resource
│ │ │ └── ProductResource.java
│ └── resources
│ │ ├── application.yml
│ │ ├── banner.txt
│ │ └── logback-spring.xml
│ └── test
│ └── java
│ └── com
│ └── tanerdiler
│ └── microservice
│ └── product
│ └── ContainerizedProductsApplicationTests.java
├── containerized-prometheus
└── config
│ └── prometheus.yml
├── docker-compose.yml
├── mvnw
├── mvnw.cmd
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | .java-version
2 | elasticsearch
3 | /target/
4 | /**/target
5 | /**/.DS_Store
6 | !.mvn/wrapper/maven-wrapper.jar
7 |
8 | ### STS ###
9 | .apt_generated
10 | .classpath
11 | .factorypath
12 | .project
13 | .settings
14 | .springBeans
15 | .sts4-cache
16 |
17 | ### IntelliJ IDEA ###
18 | .idea
19 | *.iws
20 | *.iml
21 | *.ipr
22 |
23 | ### NetBeans ###
24 | /nbproject/private/
25 | /build/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Taner Diler
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SPRING BOOT MICROCSERVICE USING SPRING CLOUD, EUREKA, RIBBON, ZUUL, ZIPKIN, SLEUTH
2 |
3 | This project is created to get experience on **Microservices With Netflix OSS**. This is a simple project by coded imperative programming with simple business requirements.
4 |
5 | ELK Stack has been integrated for monitoring since version 1.1.0.
6 |
7 | ## There are four microservices:
8 |
9 | - **Accounts** : This microservice is responsible for managing accounts. An account could be buyer, seller or an backoffice account but there is only buyer account.
10 | - **Products** : This microservice is responsible for managing products.
11 | - **Orders** : This microservice is responsible for managing orders. It doesn't know anything about account and product except id.
12 | - **Backoffice**: This microservice is provides endpoints for backoffice ui.
13 |
14 | Backoffice microservice has an endpoint with path "/api/v1/backoffice/orders". This endpoint return a list of orders with name of product and account. It connects accounts, products and orders
15 | microservices via **Feign**.
16 |
17 | ### EndPoints ###
18 |
19 | | Service | EndPoint | Port | Method | Description |
20 | | ------------- | -----------------------------| :-----: | :-----:| ------------------------------------------------ |
21 | | Accounts | /api/v1/accounts/{id} | 7500 | GET | Return detail of specified account |
22 | | Accounts | /api/v1/accounts | 7500 | GET | Return details of all acounts |
23 | | Products | /api/v1/products/{id} | 7501 | GET | Return detail of specified product |
24 | | Products | /api/v1/products | 7501 | GET | Return details of all products |
25 | | Orders | /api/v1/orders/{id} | 7502 | GET | Return detail of order |
26 | | Orders | /api/v1/orders | 7502 | GET | Return details of orders |
27 | | Backoffice | /api/v1/backoffice/orders | 7503 | GET | Return orders with product name and account name |
28 |
29 | ### Gateways ###
30 |
31 | | Service | EndPoint |
32 | | ------------- | :---------------------------------------: |
33 | | Accounts | **/account**/api/v1/accounts/{id} |
34 | | Accounts | **/account**/api/v1/accounts |
35 | | Products | **/product**/api/v1/products/{id} |
36 | | Products | **/product**/api/v1/products |
37 | | Orders | **/order**/api/v1/orders/{id} |
38 | | Orders | **/order**/api/v1/orders |
39 | | Backoffice | **/backoffice**/api/v1/backoffice/orders |
40 |
41 | URI for gateway : *http://localhost:8762*
42 |
43 | ## Used Netflix OSS:
44 |
45 | - **Netflix Eureka** is used for discovery service.
46 | - **Netflix Ribbon** is used for client side load-balancing.
47 | - **Netflix Zuul** is used for gateway.
48 |
49 | ## Distributed Tracing:
50 |
51 | - **Sleuth** and **Zipkin**
52 |
53 | You can open Zipkin : http://localhost:9411
54 | 
55 | 
56 |
57 | ## Used ELK STACK:
58 |
59 | - **ElasticSearch** is on 6972 port
60 | - **Logstash TCP** is on 5000 port
61 | - **Kibana** is on 5601 port
62 |
63 | Open kibana with http://localhost:5601/. You must define an index pattern (taner-*) on Management/Stack Management.
64 |
65 | 
66 |
67 | ## Used Grafana
68 |
69 | You can open Grafana : http://localhost:3000/
70 | Predefined dashboard : http://localhost:3000/d/dLsDQIUnzb/spring-boot-observability?orgId=1&refresh=5s
71 |
72 | Grafana has loki for log aggregation and tempo for distributed tracing backend.
73 |
74 |
75 | ## Build & Run
76 |
77 | - *>mvn clean package* : to build
78 | - *>docker-compose up* --build : build docker images and containers and run containers
79 | - *>docker-compose stop* : stop the dockerized services
80 | - Each maven module has a Dockerfile.
81 |
82 | In docker-compose.yml file:
83 |
84 | - Accounts Service : **__2222__** port is mapped to **__7500__** port of host
85 | - Products Service : **__2222__** port is mapped to **__7501__** port of host
86 | - Orders Service : **__2222__** port is mapped to **__7502__** port of host
87 | - Backoffice Service : **__2222__** port is mapped to **__7503__** port of host
88 | - Eureka Discovery Service : **__8761__** port is mapped to **__8761__** port of host
89 | - Spring Boot (/ Zuul) Gateway Service : **__8762__** port is mapped to **__8762__** port of host
90 |
91 | ## KUBERNETES
92 |
93 | - kubectl create -f containerized-accounts/k8n/deployment.yml
94 | - kubectl create -f containerized-accounts/k8n/service.yml
95 | - kubectl port-forward svc/containerized-accounts 7500:7500
96 | - curl localhost:7500/account/api/v1/accounts
97 |
98 | - kubectl create -f containerized-products/k8n/deployment.yml
99 | - kubectl create -f containerized-products/k8n/service.yml
100 | - kubectl port-forward svc/containerized-products 7501:7501
101 | - curl http://localhost:7501/product/api/v1/products
102 |
103 | - kubectl create -f containerized-orders/k8n/deployment.yml
104 | - kubectl create -f containerized-orders/k8n/service.yml
105 | - kubectl port-forward svc/containerized-orders 7502:7502
106 | - curl localhost:7502/order/api/v1/orders
107 |
108 | - kubectl create -f containerized-main/k8n/deployment.yml
109 | - kubectl create -f containerized-main/k8n/service.yml
110 | - kubectl port-forward svc/containerized-main 7503:7503
111 | - curl localhost:7503/backoffice/api/v1/backoffice/orders
112 |
113 | - kubectl create -f containerized-discovery/k8n/deployment.yml
114 | - kubectl create -f containerized-discovery/k8n/service.yml
115 | - kubectl port-forward svc/discovery 8761:8761
116 |
117 | - kubectl create -f containerized-gateway/k8n/deployment.yml
118 | - kubectl create -f containerized-gateway/k8n/service.yml
119 | - kubectl port-forward svc/gateway 8762:8762
120 | - curl localhost:8762/backoffice/api/v1/backoffice/orders
121 |
122 | ## VERSIONS
123 |
124 | ### 2.0.2
125 | - feign-micrometer dependency and Capability bean added to send trace-id on resttemplate calls
126 |
127 | @Bean
128 | public Capability capability(final MeterRegistry registry) {
129 | return new MicrometerCapability(registry);
130 | }
131 |
132 |
133 | io.github.openfeign
134 | feign-micrometer
135 |
136 | - micrometer-tracing-bridge-brave added to generate trace-id and span-id
137 |
138 |
139 | io.micrometer
140 | micrometer-tracing-bridge-brave
141 |
142 | - Integrate Grafana OSS : Grafana, Loki, Tempo
143 |
144 | ### 2.0.1
145 |
146 | - Update Spring-Boot version to 3.2.1
147 | - Start to use micrometer tracing
148 | - Zipkin will be replaced by Grafana
149 |
150 | ### 2.0.0
151 |
152 | - Add kubernetes yaml files (still using Eureka discovery)
153 |
154 | ### 1.3.0
155 | - Update Spring Boot version to 2.5.1
156 | - Switch to Spring Boot Gateway
157 |
158 | ### 1.2.0
159 | - Sleuth and Zipkin Integration
160 | - Making some refactorings
161 | - Lombok Integration
162 |
163 | ### 1.1.0
164 |
165 | - ElasticSearch, Kibana, Logstash integration
166 |
167 | ### 1.0.0 SNAPSHOT
168 |
169 | - Spring-Boot 2.3.1.RELEASE
170 | - Java 11
171 | - Docker Image updated
172 | - Spring-Cloud artifacts have been changed
173 | - Open Feign integrated
174 |
175 | ### 0.0.1
176 |
177 | - Spring-Boot 2.0.2.RELEASE
178 | - Java 8
179 |
180 | ## RESOURCES
181 |
182 | - ![RestTemplate & Micrometer & OpenFeign (https://www.appsdeveloperblog.com/micrometer-and-zipkin-in-spring-boot/#google_vignette)]
183 |
--------------------------------------------------------------------------------
/agents/opentelemetry-javaagent.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/agents/opentelemetry-javaagent.jar
--------------------------------------------------------------------------------
/assets/kibana-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/assets/kibana-1.png
--------------------------------------------------------------------------------
/assets/zipkin-1_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/assets/zipkin-1_0.png
--------------------------------------------------------------------------------
/assets/zipkin-1_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/assets/zipkin-1_1.png
--------------------------------------------------------------------------------
/containerized-accounts/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/containerized-accounts/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-accounts/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/containerized-accounts/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/containerized-accounts/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:20.0.2_9-jre-alpine
2 | MAINTAINER Taner Diler
3 | ADD target/containerized-accounts.jar containerized-accounts.jar
4 | ENTRYPOINT ["java", "-jar", "/containerized-accounts.jar"]
5 | EXPOSE 2222
--------------------------------------------------------------------------------
/containerized-accounts/k8n/deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: k8n-service-accounts
5 | labels:
6 | app: k8n-service-accounts
7 | spec:
8 | replicas: 3
9 | selector:
10 | matchLabels:
11 | app: k8n-service-accounts
12 | template:
13 | metadata:
14 | labels:
15 | app: k8n-service-accounts
16 | spec:
17 | containers:
18 | - name: containerized-accounts
19 | image: tanerdiler/service-accounts-api:latest
20 | imagePullPolicy: Never
21 | ports:
22 | - containerPort: 2222
--------------------------------------------------------------------------------
/containerized-accounts/k8n/service.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: containerized-accounts
5 | spec:
6 | selector:
7 | app: k8n-service-accounts
8 | ports:
9 | - protocol: TCP
10 | port: 7500
11 | targetPort: 2222
--------------------------------------------------------------------------------
/containerized-accounts/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/containerized-accounts/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/containerized-accounts/opentelemetry-javaagent.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-accounts/opentelemetry-javaagent.jar
--------------------------------------------------------------------------------
/containerized-accounts/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.tanerdiler.microservice
7 | containerized-microservices
8 | 2.0.1
9 |
10 |
11 | containerized-accounts
12 | jar
13 |
14 | containerized-accounts
15 | Demo project for Spring Boot
16 |
17 |
18 |
19 | io.opentelemetry
20 | opentelemetry-bom
21 | 1.27.0
22 | pom
23 | import
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-actuator
36 |
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-netflix-eureka-client
41 |
42 |
43 |
44 |
45 | com.sun.jersey.contribs
46 | jersey-apache-client4
47 | 1.19.4
48 |
49 |
50 |
51 | io.micrometer
52 | micrometer-tracing-bridge-brave
53 |
54 |
55 | io.zipkin.reporter2
56 | zipkin-reporter-brave
57 |
58 |
59 | io.micrometer
60 | micrometer-registry-prometheus
61 |
62 |
63 | io.opentelemetry
64 | opentelemetry-api
65 |
66 |
67 | io.opentelemetry.javaagent
68 | opentelemetry-javaagent
69 | 1.27.0
70 |
71 |
72 |
73 |
74 | net.logstash.logback
75 | logstash-logback-encoder
76 | ${logtash-logback-encoder.version}
77 |
78 |
79 |
80 |
81 | org.springframework.boot
82 | spring-boot-starter-test
83 |
84 |
85 |
86 |
87 | org.projectlombok
88 | lombok
89 |
90 |
91 |
92 |
93 | containerized-accounts
94 |
95 |
96 | org.springframework.boot
97 | spring-boot-maven-plugin
98 |
99 |
100 | org.apache.maven.plugins
101 | maven-compiler-plugin
102 | ${maven.compiler.version}
103 |
104 | ${java.version}
105 |
106 |
107 | org.projectlombok
108 | lombok
109 | ${lombok.version}
110 |
111 |
112 | 19
113 | 19
114 |
115 |
116 |
117 | org.apache.maven.plugins
118 | maven-surefire-plugin
119 | ${maven.surefire.version}
120 |
121 |
122 | --illegal-access=permit
123 |
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-failsafe-plugin
129 | ${maven.surefire.version}
130 |
131 |
132 | --illegal-access=permit
133 |
134 |
135 |
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/containerized-accounts/src/main/java/com/tanerdiler/microservice/accounts/ContainerizedAccountsApplication.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.accounts;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | @SpringBootApplication
8 | @EnableDiscoveryClient
9 | public class ContainerizedAccountsApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ContainerizedAccountsApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/containerized-accounts/src/main/java/com/tanerdiler/microservice/accounts/config/Config.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.accounts.config;
2 |
3 | import io.prometheus.client.exemplars.tracer.otel_agent.OpenTelemetryAgentSpanContextSupplier;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class Config {
9 | @Bean
10 | public OpenTelemetryAgentSpanContextSupplier openTelemetryAgentSpanContextSupplier() {
11 | return new OpenTelemetryAgentSpanContextSupplier();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/containerized-accounts/src/main/java/com/tanerdiler/microservice/accounts/model/Account.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.accounts.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | @Data
7 | @AllArgsConstructor
8 | public class Account {
9 |
10 | private Integer id;
11 | private String fullname;
12 | private String email;
13 | }
14 |
--------------------------------------------------------------------------------
/containerized-accounts/src/main/java/com/tanerdiler/microservice/accounts/repository/AccountRepository.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.accounts.repository;
2 |
3 | import com.tanerdiler.microservice.accounts.model.Account;
4 | import org.springframework.stereotype.Repository;
5 |
6 | import java.util.Collection;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 | import java.util.Optional;
10 |
11 | @Repository
12 | public class AccountRepository
13 | {
14 | private final static Map accounts = new HashMap<>();
15 |
16 | static {
17 | accounts.put(1, new Account(1, "Taner Diler", "taner.diler@gmail.com"));
18 | accounts.put(2, new Account(2, "John Doe", "john.doe@mail.com"));
19 | accounts.put(3, new Account(3, "Michael Knight", "michael.knight@mail.com"));
20 | accounts.put(4, new Account(4, "Black Hawk", "black.hawk@mail.com"));
21 | }
22 |
23 | public Optional findById(Integer id)
24 | {
25 | return Optional.ofNullable(accounts.get(id));
26 | }
27 |
28 | public Optional> findAll() {
29 | return Optional.ofNullable(accounts.values());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/containerized-accounts/src/main/java/com/tanerdiler/microservice/accounts/resource/AccountResource.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.accounts.resource;
2 |
3 | import static java.lang.String.format;
4 | import com.tanerdiler.microservice.accounts.model.Account;
5 | import com.tanerdiler.microservice.accounts.repository.AccountRepository;
6 | import lombok.AllArgsConstructor;
7 | import lombok.RequiredArgsConstructor;
8 | import lombok.extern.slf4j.Slf4j;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.annotation.GetMapping;
11 | import org.springframework.web.bind.annotation.PathVariable;
12 | import org.springframework.web.bind.annotation.RequestMapping;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | import java.util.ArrayList;
16 | import java.util.Collection;
17 | import java.util.Random;
18 |
19 | @Slf4j
20 | @RestController
21 | @RequestMapping("/api/v1/accounts")
22 | @RequiredArgsConstructor
23 | public class AccountResource
24 | {
25 | private final AccountRepository repository;
26 | private Random random = new Random();
27 |
28 | @GetMapping("/{id}")
29 | public ResponseEntity get(@PathVariable("id") Integer id)
30 | {
31 | // if (random.nextInt(100)<30) {
32 | // throw new RuntimeException(format("Account{%d} not found!", id));
33 | // }
34 | final var account = repository.findById(id).get();
35 | log.info("Account {} detail fetched {}", id, account);
36 | return ResponseEntity.ok(account);
37 | }
38 |
39 | @GetMapping()
40 | public ResponseEntity> getAll()
41 | {
42 | // if (random.nextInt(100)<30) {
43 | // throw new RuntimeException("Datasource not reached to fetch accounts!");
44 | // }
45 | final var accounts = (repository.findAll().get());
46 | log.info("Executing fetching all accounts {}", accounts);
47 | return ResponseEntity.ok(accounts);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/containerized-accounts/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: ${PORT:2222}
3 | servlet:
4 | context-path: /account
5 |
6 | spring:
7 | application:
8 | name: containerized-accounts
9 | logstash:
10 | server: logstash
11 | port: 5000
12 | sleuth:
13 | traceId128: true
14 | supportsJoin: false
15 |
16 | management:
17 | endpoints:
18 | web:
19 | exposure:
20 | include: prometheus
21 | metrics:
22 | tags:
23 | application: app
24 | distribution:
25 | percentiles-histogram:
26 | http:
27 | server:
28 | requests: 'true'
29 | logging:
30 | pattern:
31 | level: "trace_id=%X{traceId:-} span_id=%X{spanId:-} trace_flags=%X{trace_flags} %p"
32 | level:
33 | com.tanerdiler.microservice.accounts: DEBUG
34 | org.springframework: WARN
35 | org.hibernate: WARN
36 |
37 | eureka:
38 | instance:
39 | prefer-ip-address: true
40 | client:
41 | register-with-eureka: true
42 | fetch-registry: true
43 | serviceUrl:
44 | defaultZone: ${DISCOVERY_URL:http://discovery:8761}/eureka/
45 |
46 | ribbon:
47 | eureka:
48 | enabled: true
--------------------------------------------------------------------------------
/containerized-accounts/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | _ _ ____ _
2 | / \ ___ ___ ___ _ _ _ __ | |_ / ___| ___ _ __ __ __ (_) ___ ___
3 | / _ \ / __| / __| / _ \ | | | | | '_ \ | __| \___ \ / _ \ | '__| \ \ / / | | / __| / _ \
4 | / ___ \ | (__ | (__ | (_) | | |_| | | | | | | |_ ___) | | __/ | | \ V / | | | (__ | __/
5 | /_/ \_\ \___| \___| \___/ \__,_| |_| |_| \__| |____/ \___| |_| \_/ |_| \___| \___|
6 |
--------------------------------------------------------------------------------
/containerized-accounts/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ${LOG_FILE}
16 |
17 | ${FILE_LOG_PATTERN}
18 |
19 |
20 | ${LOG_FILE_ARCHIVE}-%d{yyyy-MM-dd}.%i.gz
21 | ${LOG_FILE_MAX_HISTORY:-0}
22 |
23 | ${LOG_FILE_MAX_SIZE:-10MB}
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | ${logstash-server:- }:${logstash-port:- }
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/containerized-accounts/src/test/java/com/tanerdiler/microservice/accounts/ContainerizedAccountsApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.accounts;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.junit.jupiter.api.Test;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 |
7 | @SpringBootTest
8 | public class ContainerizedAccountsApplicationTests {
9 |
10 | @Test
11 | public void contextLoads() {
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/containerized-discovery/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/containerized-discovery/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-discovery/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/containerized-discovery/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/containerized-discovery/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:20.0.2_9-jre-alpine
2 | MAINTAINER Taner Diler
3 | ADD target/containerized-discovery.jar containerized-discovery.jar
4 | ENTRYPOINT ["java", "-jar", "/containerized-discovery.jar"]
5 | EXPOSE 8761
6 |
--------------------------------------------------------------------------------
/containerized-discovery/k8n/deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: k8n-service-discovery
5 | labels:
6 | app: k8n-service-discovery
7 | spec:
8 | replicas: 3
9 | selector:
10 | matchLabels:
11 | app: k8n-service-discovery
12 | template:
13 | metadata:
14 | labels:
15 | app: k8n-service-discovery
16 | spec:
17 | containers:
18 | - name: containerized-discovery
19 | image: tanerdiler/service-discovery:latest
20 | imagePullPolicy: Never
21 | ports:
22 | - containerPort: 8761
--------------------------------------------------------------------------------
/containerized-discovery/k8n/service.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: discovery
5 | spec:
6 | selector:
7 | app: k8n-service-discovery
8 | ports:
9 | - protocol: TCP
10 | port: 8761
11 | targetPort: 8761
--------------------------------------------------------------------------------
/containerized-discovery/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/containerized-discovery/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/containerized-discovery/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.tanerdiler.microservice
7 | containerized-microservices
8 | 2.0.1
9 |
10 |
11 | containerized-discovery
12 | jar
13 |
14 | containerized-discovery
15 | Eureka Discovery Server
16 |
17 |
18 |
19 | org.springframework.boot
20 | spring-boot-starter-actuator
21 |
22 |
23 | org.springframework.cloud
24 | spring-cloud-starter-netflix-eureka-server
25 |
26 |
27 |
28 | org.apache.httpcomponents
29 | httpclient
30 | 4.5.12
31 |
32 |
33 | net.logstash.logback
34 | logstash-logback-encoder
35 | ${logtash-logback-encoder.version}
36 |
37 |
38 |
39 | io.micrometer
40 | micrometer-tracing-bridge-brave
41 |
42 |
43 | io.zipkin.reporter2
44 | zipkin-reporter-brave
45 |
46 |
47 | io.micrometer
48 | micrometer-registry-prometheus
49 |
50 |
51 | io.opentelemetry
52 | opentelemetry-api
53 |
54 |
55 |
56 |
57 | containerized-discovery
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-maven-plugin
62 |
63 |
64 | org.apache.maven.plugins
65 | maven-compiler-plugin
66 | ${maven.compiler.version}
67 |
68 | ${java.version}
69 |
70 |
71 | org.projectlombok
72 | lombok
73 | ${lombok.version}
74 |
75 |
76 | 19
77 | 19
78 |
79 |
80 |
81 | org.apache.maven.plugins
82 | maven-surefire-plugin
83 | ${maven.surefire.version}
84 |
85 |
86 | --illegal-access=permit
87 |
88 |
89 |
90 |
91 | org.apache.maven.plugins
92 | maven-failsafe-plugin
93 | ${maven.surefire.version}
94 |
95 |
96 | --illegal-access=permit
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/containerized-discovery/src/main/java/com/tanerdiler/microservice/discovery/ContainerizedDiscoveryApplication.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.discovery;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6 |
7 | @SpringBootApplication
8 | @EnableEurekaServer
9 | public class ContainerizedDiscoveryApplication
10 | {
11 | public static void main(String[] args) {
12 | SpringApplication.run(ContainerizedDiscoveryApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/containerized-discovery/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: ${PORT:8761}
3 |
4 | eureka:
5 | instance:
6 | hostname: discovery
7 | client:
8 | registerWithEureka: false
9 | fetchRegistry: false
10 | server:
11 | enableSelfPreservation: false
12 |
13 | spring:
14 | application:
15 | name: containerized-discovery
16 | logstash:
17 | server: logstash
18 | port: 5000
19 | sleuth:
20 | traceId128: true
21 | supportsJoin: false
22 |
23 | management:
24 | endpoints:
25 | web:
26 | exposure:
27 | include: "*"
28 |
29 | metrics:
30 | distribution:
31 | percentiles-histogram.http.server.requests: false
32 | percentiles.http.server.requests: 0.5, 0.9, 0.95, 0.99, 0.999
33 | sla.http.server.requests: 500ms, 2000ms
34 |
--------------------------------------------------------------------------------
/containerized-discovery/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ____ _ ____ _
2 | | _ \ (_) ___ ___ ___ __ __ ___ _ __ _ _ / ___| ___ _ __ __ __ (_) ___ ___
3 | | | | | | | / __| / __| / _ \ \ \ / / / _ \ | '__| | | | | \___ \ / _ \ | '__| \ \ / / | | / __| / _ \
4 | | |_| | | | \__ \ | (__ | (_) | \ V / | __/ | | | |_| | ___) | | __/ | | \ V / | | | (__ | __/
5 | |____/ |_| |___/ \___| \___/ \_/ \___| |_| \__, | |____/ \___| |_| \_/ |_| \___| \___|
6 | |___/
--------------------------------------------------------------------------------
/containerized-discovery/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ${LOG_FILE}
16 |
17 | ${FILE_LOG_PATTERN}
18 |
19 |
20 | ${LOG_FILE_ARCHIVE}-%d{yyyy-MM-dd}.%i.gz
21 | ${LOG_FILE_MAX_HISTORY:-0}
22 |
23 | ${LOG_FILE_MAX_SIZE:-10MB}
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/containerized-gateway/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/containerized-gateway/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-gateway/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/containerized-gateway/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/containerized-gateway/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:20.0.2_9-jre-alpine
2 | MAINTAINER Taner Diler
3 | ADD target/containerized-gateway.jar containerized-gateway.jar
4 | ENTRYPOINT ["java", "-jar", "/containerized-gateway.jar"]
5 | EXPOSE 8762
6 |
--------------------------------------------------------------------------------
/containerized-gateway/k8n/deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: k8n-service-gateway
5 | labels:
6 | app: k8n-service-gateway
7 | spec:
8 | replicas: 3
9 | selector:
10 | matchLabels:
11 | app: k8n-service-gateway
12 | template:
13 | metadata:
14 | labels:
15 | app: k8n-service-gateway
16 | spec:
17 | containers:
18 | - name: containerized-gateway
19 | image: tanerdiler/service-gateway:latest
20 | imagePullPolicy: Never
21 | ports:
22 | - containerPort: 8762
--------------------------------------------------------------------------------
/containerized-gateway/k8n/service.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: gateway
5 | spec:
6 | selector:
7 | app: k8n-service-gateway
8 | ports:
9 | - protocol: TCP
10 | port: 8762
11 | targetPort: 8762
--------------------------------------------------------------------------------
/containerized-gateway/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/containerized-gateway/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/containerized-gateway/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.tanerdiler.microservice
7 | containerized-microservices
8 | 2.0.1
9 |
10 |
11 | containerized-gateway
12 | jar
13 |
14 | containerized-gateway
15 | Gateway project
16 |
17 |
18 |
19 | org.springframework.boot
20 | spring-boot-starter-actuator
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-gateway
26 |
27 |
28 |
29 | org.springframework.cloud
30 | spring-cloud-starter-netflix-eureka-client
31 |
32 |
33 |
34 | io.micrometer
35 | micrometer-tracing-bridge-brave
36 |
37 |
38 | io.zipkin.reporter2
39 | zipkin-reporter-brave
40 |
41 |
42 | io.micrometer
43 | micrometer-registry-prometheus
44 |
45 |
46 | io.opentelemetry
47 | opentelemetry-api
48 |
49 |
50 |
51 | net.logstash.logback
52 | logstash-logback-encoder
53 | ${logtash-logback-encoder.version}
54 |
55 |
56 |
57 |
58 | containerized-gateway
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-maven-plugin
63 |
64 |
65 | org.apache.maven.plugins
66 | maven-compiler-plugin
67 | ${maven.compiler.version}
68 |
69 | ${java.version}
70 |
71 |
72 | org.projectlombok
73 | lombok
74 | ${lombok.version}
75 |
76 |
77 | 19
78 | 19
79 |
80 |
81 |
82 | org.apache.maven.plugins
83 | maven-surefire-plugin
84 | ${maven.surefire.version}
85 |
86 |
87 | --illegal-access=permit
88 |
89 |
90 |
91 |
92 | org.apache.maven.plugins
93 | maven-failsafe-plugin
94 | ${maven.surefire.version}
95 |
96 |
97 | --illegal-access=permit
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/containerized-gateway/src/main/java/com/tanerdiler/microservice/gateway/ContainerizedGatewayApplication.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.gateway;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ContainerizedGatewayApplication
8 | {
9 | public static void main(String[] args) {
10 | SpringApplication.run(ContainerizedGatewayApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/containerized-gateway/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: ${PORT:8762}
3 |
4 | spring:
5 | application:
6 | name: containerized-gateway
7 | logstash:
8 | server: logstash
9 | port: 5000
10 | sleuth:
11 | traceId128: true
12 | supportsJoin: false
13 | cloud:
14 | gateway:
15 | routes:
16 | - id: containerized-main
17 | uri: lb://CONTAINERIZED-MAIN
18 | predicates:
19 | - Path=/backoffice/**
20 | - id: CONTAINERIZED-accounts
21 | uri: lb://CONTAINERIZED-ACCOUNTS
22 | predicates:
23 | - Path=/account/**
24 | - id: containerized-orders
25 | uri: lb://CONTAINERIZED-ORDERS
26 | predicates:
27 | - Path=/order/**
28 | - id: containerized-products
29 | uri: lb://CONTAINERIZED-PRODUCTS
30 | predicates:
31 | - Path=/product/**
32 |
33 | management:
34 | endpoints:
35 | web:
36 | exposure:
37 | include: "*"
38 |
39 | metrics:
40 | distribution:
41 | percentiles-histogram.http.server.requests: false
42 | percentiles.http.server.requests: 0.5, 0.9, 0.95, 0.99, 0.999
43 | sla.http.server.requests: 500ms, 2000ms
44 |
45 | eureka:
46 | instance:
47 | prefer-ip-address: true
48 | client:
49 | registerWithEureka: false
50 | serviceUrl:
51 | defaultZone: ${DISCOVERY_URL:http://discovery:8761}/eureka
52 |
53 | # Increase the Hystrix timeout to 60s (globally)
54 | hystrix:
55 | command:
56 | default:
57 | execution:
58 | isolation:
59 | thread:
60 | timeoutInMilliseconds: 60000
61 |
--------------------------------------------------------------------------------
/containerized-gateway/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ____ _ ____ _
2 | / ___| __ _ | |_ ___ __ __ __ _ _ _ / ___| ___ _ __ __ __ (_) ___ ___
3 | | | _ / _` | | __| / _ \ \ \ /\ / / / _` | | | | | \___ \ / _ \ | '__| \ \ / / | | / __| / _ \
4 | | |_| | | (_| | | |_ | __/ \ V V / | (_| | | |_| | ___) | | __/ | | \ V / | | | (__ | __/
5 | \____| \__,_| \__| \___| \_/\_/ \__,_| \__, | |____/ \___| |_| \_/ |_| \___| \___|
6 | |___/
--------------------------------------------------------------------------------
/containerized-gateway/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ${LOG_FILE}
16 |
17 | ${FILE_LOG_PATTERN}
18 |
19 |
20 | ${LOG_FILE_ARCHIVE}-%d{yyyy-MM-dd}.%i.gz
21 | ${LOG_FILE_MAX_HISTORY:-0}
22 |
23 | ${LOG_FILE_MAX_SIZE:-10MB}
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/containerized-grafana/etc/dashboards.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: 1
2 | providers:
3 | - name: 'Spring Boot Observability'
4 | orgId: 1
5 | folder: ''
6 | type: 'file'
7 | disableDeletion: true
8 | editable: true
9 | options:
10 | path: '/etc/grafana/dashboards'
11 |
--------------------------------------------------------------------------------
/containerized-grafana/etc/grafana/datasource.yml:
--------------------------------------------------------------------------------
1 | # config file version
2 | apiVersion: 1
3 |
4 | # list of datasources that should be deleted from the database
5 | deleteDatasources:
6 | - name: Prometheus
7 | orgId: 1
8 |
9 | # list of datasources to insert/update depending
10 | # what's available in the database
11 | datasources:
12 | # name of the datasource. Required
13 | - uid: prometheus
14 | orgId: 1
15 | name: Prometheus
16 | type: prometheus
17 | typeName: Prometheus
18 | access: proxy
19 | url: http://prometheus:9090
20 | password: ''
21 | user: ''
22 | database: ''
23 | basicAuth: false
24 | isDefault: true
25 | jsonData:
26 | exemplarTraceIdDestinations:
27 | - datasourceUid: tempo
28 | name: trace_id
29 | httpMethod: POST
30 | readOnly: false
31 | editable: true
32 | - uid: tempo
33 | orgId: 1
34 | name: Tempo
35 | type: tempo
36 | typeName: Tempo
37 | access: proxy
38 | url: http://tempo
39 | password: ''
40 | user: ''
41 | database: ''
42 | basicAuth: false
43 | isDefault: false
44 | jsonData:
45 | nodeGraph:
46 | enabled: true
47 | search:
48 | hide: false
49 | tracesToLogs:
50 | datasourceUid: loki
51 | filterBySpanID: false
52 | filterByTraceID: true
53 | mapTagNamesEnabled: false
54 | tags:
55 | - compose_service
56 | readOnly: false
57 | editable: true
58 | - uid: loki
59 | orgId: 1
60 | name: Loki
61 | type: loki
62 | typeName: Loki
63 | access: proxy
64 | url: http://loki:3100
65 | password: ''
66 | user: ''
67 | database: ''
68 | basicAuth: false
69 | isDefault: false
70 | jsonData:
71 | derivedFields:
72 | - datasourceUid: tempo
73 | matcherRegex: (?:trace_id)=(\w+)
74 | name: TraceID
75 | url: $${__value.raw}
76 | readOnly: false
77 | editable: true
78 |
--------------------------------------------------------------------------------
/containerized-logstash/config/logstash.yml:
--------------------------------------------------------------------------------
1 |
2 | ---
3 | ## Default Logstash configuration from logstash-docker.
4 | ## from https://github.com/elastic/logstash-docker/blob/master/build/logstash/config/logstash-oss.yml
5 | #
6 | http.host: "0.0.0.0"
7 | path.config: /usr/share/logstash/pipeline
--------------------------------------------------------------------------------
/containerized-logstash/pipeline/logstash.conf:
--------------------------------------------------------------------------------
1 | input {
2 | tcp {
3 | port => 5000
4 | add_field => [ "source", "taner-api" ]
5 | codec => json_lines
6 | }
7 | }
8 |
9 |
10 | ## Add your filters / logstash plug ins configuration here
11 | filter {
12 | ### getting all fields that where extracted from logstash-logback-plugin
13 | #json {
14 | # source => "message"
15 | #}
16 | ### filter out keep-alive-messages, that have no valid JSON-format and produce _jsonparsefailure in tags
17 | if "_jsonparsefailure" in [tags] {
18 | drop { }
19 | }
20 | }
21 |
22 | output {
23 | if [source] == "taner-api" {
24 | elasticsearch {
25 | hosts => [ "elasticsearch:9200"]
26 | index => "taner-api-%{+YYYY.MM.dd}"
27 | ssl => false
28 | ssl_certificate_verification => false
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/containerized-main/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/containerized-main/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-main/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/containerized-main/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/containerized-main/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:20.0.2_9-jre-alpine
2 | MAINTAINER Taner Diler
3 | ADD target/containerized-main.jar containerized-main.jar
4 | ENTRYPOINT ["java", "-jar", "/containerized-main.jar"]
5 | EXPOSE 2222
6 |
--------------------------------------------------------------------------------
/containerized-main/k8n/deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: k8n-service-main
5 | labels:
6 | app: k8n-service-main
7 | spec:
8 | replicas: 3
9 | selector:
10 | matchLabels:
11 | app: k8n-service-main
12 | template:
13 | metadata:
14 | labels:
15 | app: k8n-service-main
16 | spec:
17 | containers:
18 | - name: containerized-main
19 | image: tanerdiler/service-main-api:latest
20 | imagePullPolicy: Never
21 | ports:
22 | - containerPort: 2222
--------------------------------------------------------------------------------
/containerized-main/k8n/service.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: containerized-main
5 | spec:
6 | selector:
7 | app: k8n-service-main
8 | ports:
9 | - protocol: TCP
10 | port: 7503
11 | targetPort: 2222
--------------------------------------------------------------------------------
/containerized-main/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/containerized-main/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/containerized-main/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.tanerdiler.microservice
7 | containerized-microservices
8 | 2.0.1
9 |
10 |
11 | containerized-main
12 | jar
13 |
14 | containerized-main
15 | Main api for Spring Boot
16 |
17 |
18 |
19 | io.opentelemetry
20 | opentelemetry-bom
21 | 1.27.0
22 | pom
23 | import
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.cloud
35 | spring-cloud-starter-openfeign
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-actuator
41 |
42 |
43 |
44 | org.springframework.cloud
45 | spring-cloud-starter-netflix-eureka-client
46 |
47 |
48 |
49 |
50 | com.sun.jersey.contribs
51 | jersey-apache-client4
52 | 1.19.4
53 |
54 |
55 |
56 | io.micrometer
57 | micrometer-tracing-bridge-brave
58 |
59 |
60 | io.zipkin.reporter2
61 | zipkin-reporter-brave
62 |
63 |
64 | io.github.openfeign
65 | feign-micrometer
66 |
67 |
68 |
69 | io.micrometer
70 | micrometer-registry-prometheus
71 |
72 |
73 | io.opentelemetry
74 | opentelemetry-api
75 |
76 |
77 | io.opentelemetry.javaagent
78 | opentelemetry-javaagent
79 | 1.27.0
80 |
81 |
82 |
83 |
84 | net.logstash.logback
85 | logstash-logback-encoder
86 | ${logtash-logback-encoder.version}
87 |
88 |
89 |
90 |
91 | org.springframework.boot
92 | spring-boot-starter-test
93 |
94 |
95 |
96 |
97 | org.projectlombok
98 | lombok
99 |
100 |
101 |
102 |
103 | containerized-main
104 |
105 |
106 | org.springframework.boot
107 | spring-boot-maven-plugin
108 |
109 |
110 | org.apache.maven.plugins
111 | maven-compiler-plugin
112 | ${maven.compiler.version}
113 |
114 | ${java.version}
115 |
116 |
117 | org.projectlombok
118 | lombok
119 | ${lombok.version}
120 |
121 |
122 | 19
123 | 19
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-surefire-plugin
129 | ${maven.surefire.version}
130 |
131 |
132 | --illegal-access=permit
133 |
134 |
135 |
136 |
137 | org.apache.maven.plugins
138 | maven-failsafe-plugin
139 | ${maven.surefire.version}
140 |
141 |
142 | --illegal-access=permit
143 |
144 |
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/ContainerizedMainApplication.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 | import org.springframework.cloud.openfeign.EnableFeignClients;
7 |
8 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @EnableFeignClients
11 | public class ContainerizedMainApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(ContainerizedMainApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/config/Config.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.config;
2 |
3 | import feign.Capability;
4 | import feign.micrometer.MicrometerCapability;
5 | import io.micrometer.core.instrument.MeterRegistry;
6 | import io.prometheus.client.exemplars.tracer.otel_agent.OpenTelemetryAgentSpanContextSupplier;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | @Configuration
11 | public class Config {
12 | @Bean
13 | public OpenTelemetryAgentSpanContextSupplier openTelemetryAgentSpanContextSupplier() {
14 | return new OpenTelemetryAgentSpanContextSupplier();
15 | }
16 |
17 | @Bean
18 | public Capability capability(final MeterRegistry registry) {
19 | return new MicrometerCapability(registry);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/dto/OrderDTO.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.dto;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class OrderDTO {
7 |
8 | private final Integer id;
9 | private final Integer count;
10 | private final Double price;
11 | private final Double discountedPrice;
12 | private final String accountName;
13 | private final String productName;
14 | }
15 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/model/Account.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class Account {
11 |
12 | private Integer id;
13 | private String fullname;
14 | private String email;
15 | }
16 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/model/Order.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @AllArgsConstructor
9 | @NoArgsConstructor
10 | public class Order {
11 |
12 | private Integer id;
13 | private Integer productId;
14 | private Integer accountId;
15 | private Integer count;
16 | private Double price;
17 | private Double discountedPrice;
18 |
19 | public Order(Integer productId, Integer accountId, Integer count, Double price, Double discountedPrice) {
20 | this.productId = productId;
21 | this.accountId = accountId;
22 | this.count = count;
23 | this.price = price;
24 | this.discountedPrice = discountedPrice;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/model/Product.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class Product {
11 |
12 | private Integer id;
13 | private String name;
14 | private Double price;
15 | }
16 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/repository/AccountServiceClient.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.repository;
2 |
3 | import com.tanerdiler.microservice.main.model.Account;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 |
9 | import java.util.List;
10 |
11 | @Component
12 | @FeignClient("containerized-accounts")
13 | public interface AccountServiceClient
14 | {
15 |
16 | @GetMapping(value = "/account/api/v1/accounts/{accountId}")
17 | Account findById(@PathVariable("accountId") Integer accountId);
18 |
19 | @GetMapping(value = "/account/api/v1/accounts")
20 | List findAll();
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/repository/OrderServiceClient.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.repository;
2 |
3 | import com.tanerdiler.microservice.main.model.Order;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 |
9 | import java.util.List;
10 |
11 | @Component
12 | @FeignClient("containerized-orders")
13 | public interface OrderServiceClient
14 | {
15 | @GetMapping(value = "/order/api/v1/orders/{orderId}")
16 | Order findById(@PathVariable("orderId") Integer orderId);
17 |
18 | @GetMapping(value = "/order/api/v1/orders")
19 | List findAll();
20 | }
21 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/repository/ProductServiceClient.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.repository;
2 |
3 | import com.tanerdiler.microservice.main.model.Product;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 |
9 | import java.util.List;
10 |
11 | @Component
12 | @FeignClient("containerized-products")
13 | public interface ProductServiceClient
14 | {
15 | @GetMapping(value = "/product/api/v1/products/{productId}")
16 | Product findById(@PathVariable("productId") Integer orderId);
17 |
18 | @GetMapping(value = "/product/api/v1/products")
19 | List findAll();
20 | }
21 |
--------------------------------------------------------------------------------
/containerized-main/src/main/java/com/tanerdiler/microservice/main/resource/BackofficeController.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main.resource;
2 |
3 | import com.tanerdiler.microservice.main.dto.OrderDTO;
4 | import com.tanerdiler.microservice.main.model.Account;
5 | import com.tanerdiler.microservice.main.model.Order;
6 | import com.tanerdiler.microservice.main.model.Product;
7 | import com.tanerdiler.microservice.main.repository.AccountServiceClient;
8 | import com.tanerdiler.microservice.main.repository.OrderServiceClient;
9 | import com.tanerdiler.microservice.main.repository.ProductServiceClient;
10 | import lombok.RequiredArgsConstructor;
11 | import lombok.extern.slf4j.Slf4j;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.web.bind.annotation.GetMapping;
14 | import org.springframework.web.bind.annotation.RequestMapping;
15 | import org.springframework.web.bind.annotation.RestController;
16 |
17 | import java.util.ArrayList;
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 |
22 | @Slf4j
23 | @RestController
24 | @RequestMapping("/api/v1/backoffice")
25 | @RequiredArgsConstructor
26 | public class BackofficeController
27 | {
28 | private final ProductServiceClient productService;
29 | private final OrderServiceClient orderService;
30 | private final AccountServiceClient accountService;
31 |
32 | @GetMapping("/orders")
33 | public ResponseEntity> getOrders()
34 | {
35 |
36 | log.warn("Fetching all orders...");
37 | List orders = orderService.findAll();
38 | Map accounts = new HashMap<>();
39 | Map products = new HashMap<>();
40 |
41 | log.warn("Fetching accounts of orders...");
42 | orders.stream()
43 | .filter(o->!accounts.containsKey(o.getAccountId()))
44 | .map(o->accountService.findById(o.getAccountId()))
45 | .forEach(a->accounts.put(a.getId(), a));
46 |
47 | log.warn("Fetching products of orders...");
48 | orders.stream()
49 | .filter(o->!products.containsKey(o.getProductId()))
50 | .map(o->productService.findById(o.getProductId()))
51 | .forEach(a->products.put(a.getId(), a));
52 |
53 | log.warn("Generating composite of orders...");
54 | List orderDTOList = new ArrayList<>();
55 | orders.forEach(o->{
56 | orderDTOList.add(new OrderDTO(
57 | o.getId(),
58 | o.getCount(),
59 | o.getPrice(),
60 | o.getDiscountedPrice(),
61 | accounts.get(o.getAccountId()).getFullname(),
62 | products.get(o.getProductId()).getName()
63 | ));
64 | });
65 |
66 | return ResponseEntity.ok(orderDTOList);
67 |
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/containerized-main/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: ${PORT:2222}
3 | servlet:
4 | context-path: /backoffice
5 |
6 | spring:
7 | application:
8 | name: containerized-main
9 | logstash:
10 | server: logstash
11 | port: 5000
12 | sleuth:
13 | traceId128: true
14 | supportsJoin: false
15 |
16 | management:
17 | endpoints:
18 | web:
19 | exposure:
20 | include: prometheus
21 | metrics:
22 | tags:
23 | application: app
24 | distribution:
25 | percentiles-histogram:
26 | http:
27 | server:
28 | requests: 'true'
29 | logging:
30 | pattern:
31 | level: "trace_id=%X{traceId:-} span_id=%X{spanId:-} trace_flags=%X{trace_flags} %p"
32 | level:
33 | com.tanerdiler.microservice.main: DEBUG
34 | org.springframework: WARN
35 | org.hibernate: WARN
36 |
37 |
38 | eureka:
39 | instance:
40 | prefer-ip-address: true
41 | client:
42 | serviceUrl:
43 | defaultZone: ${DISCOVERY_URL:http://discovery:8761}/eureka/
44 |
45 | ribbon:
46 | eureka:
47 | enabled: true
48 |
--------------------------------------------------------------------------------
/containerized-main/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | __ __ _ ____ _
2 | | \/ | __ _ (_) _ __ / ___| ___ _ __ __ __ (_) ___ ___
3 | | |\/| | / _` | | | | '_ \ \___ \ / _ \ | '__| \ \ / / | | / __| / _ \
4 | | | | | | (_| | | | | | | | ___) | | __/ | | \ V / | | | (__ | __/
5 | |_| |_| \__,_| |_| |_| |_| |____/ \___| |_| \_/ |_| \___| \___|
6 |
--------------------------------------------------------------------------------
/containerized-main/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ${LOG_FILE}
16 |
17 | ${FILE_LOG_PATTERN}
18 |
19 |
20 | ${LOG_FILE_ARCHIVE}-%d{yyyy-MM-dd}.%i.gz
21 | ${LOG_FILE_MAX_HISTORY:-0}
22 |
23 | ${LOG_FILE_MAX_SIZE:-10MB}
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | ${logstash-server:- }:${logstash-port:- }
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/containerized-main/src/test/java/com/tanerdiler/microservice/main/ContainerizedAccountsApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.main;
2 |
3 |
4 | import org.junit.jupiter.api.Test;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 |
7 |
8 |
9 | @SpringBootTest
10 | public class ContainerizedAccountsApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/containerized-orders/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/containerized-orders/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-orders/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/containerized-orders/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/containerized-orders/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:20.0.2_9-jre-alpine
2 | MAINTAINER Taner Diler
3 | ADD target/containerized-orders.jar containerized-orders.jar
4 | ENTRYPOINT ["java", "-jar", "/containerized-orders.jar"]
5 | EXPOSE 2222
6 |
--------------------------------------------------------------------------------
/containerized-orders/k8n/deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: k8n-service-orders
5 | labels:
6 | app: k8n-service-orders
7 | spec:
8 | replicas: 3
9 | selector:
10 | matchLabels:
11 | app: k8n-service-orders
12 | template:
13 | metadata:
14 | labels:
15 | app: k8n-service-orders
16 | spec:
17 | containers:
18 | - name: containerized-orders
19 | image: tanerdiler/service-orders-api:latest
20 | imagePullPolicy: Never
21 | ports:
22 | - containerPort: 2222
--------------------------------------------------------------------------------
/containerized-orders/k8n/service.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: containerized-orders
5 | spec:
6 | selector:
7 | app: k8n-service-orders
8 | ports:
9 | - protocol: TCP
10 | port: 7502
11 | targetPort: 2222
--------------------------------------------------------------------------------
/containerized-orders/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/containerized-orders/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/containerized-orders/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.tanerdiler.microservice
7 | containerized-microservices
8 | 2.0.1
9 |
10 |
11 | containerized-orders
12 | jar
13 |
14 | containerized-orders
15 | Demo project for Spring Boot
16 |
17 |
18 |
19 | io.opentelemetry
20 | opentelemetry-bom
21 | 1.27.0
22 | pom
23 | import
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-actuator
36 |
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-netflix-eureka-client
41 |
42 |
43 |
44 |
45 | com.sun.jersey.contribs
46 | jersey-apache-client4
47 | 1.19.4
48 |
49 |
50 |
51 | io.micrometer
52 | micrometer-tracing-bridge-brave
53 |
54 |
55 | io.zipkin.reporter2
56 | zipkin-reporter-brave
57 |
58 |
59 | io.micrometer
60 | micrometer-registry-prometheus
61 |
62 |
63 | io.opentelemetry
64 | opentelemetry-api
65 |
66 |
67 | io.opentelemetry.javaagent
68 | opentelemetry-javaagent
69 | 1.27.0
70 |
71 |
72 |
73 |
74 | net.logstash.logback
75 | logstash-logback-encoder
76 | ${logtash-logback-encoder.version}
77 |
78 |
79 |
80 |
81 | org.springframework.boot
82 | spring-boot-starter-test
83 |
84 |
85 |
86 |
87 | org.projectlombok
88 | lombok
89 |
90 |
91 |
92 |
93 | containerized-orders
94 |
95 |
96 | org.springframework.boot
97 | spring-boot-maven-plugin
98 |
99 |
100 | org.apache.maven.plugins
101 | maven-compiler-plugin
102 | ${maven.compiler.version}
103 |
104 | ${java.version}
105 |
106 |
107 | org.projectlombok
108 | lombok
109 | ${lombok.version}
110 |
111 |
112 | 19
113 | 19
114 |
115 |
116 |
117 | org.apache.maven.plugins
118 | maven-surefire-plugin
119 | ${maven.surefire.version}
120 |
121 |
122 | --illegal-access=permit
123 |
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-failsafe-plugin
129 | ${maven.surefire.version}
130 |
131 |
132 | --illegal-access=permit
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/java/com/tanerdiler/microservice/order/ContainerizedOrdersApplication.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.order;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | @SpringBootApplication
8 | @EnableDiscoveryClient
9 | public class ContainerizedOrdersApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ContainerizedOrdersApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/java/com/tanerdiler/microservice/order/config/Config.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.order.config;
2 |
3 | import io.prometheus.client.exemplars.tracer.otel_agent.OpenTelemetryAgentSpanContextSupplier;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class Config {
9 | @Bean
10 | public OpenTelemetryAgentSpanContextSupplier openTelemetryAgentSpanContextSupplier() {
11 | return new OpenTelemetryAgentSpanContextSupplier();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/java/com/tanerdiler/microservice/order/model/Order.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.order.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class Order {
11 |
12 | private Integer id;
13 | private Integer productId;
14 | private Integer accountId;
15 | private Integer count;
16 | private Double price;
17 | private Double discountedPrice;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/java/com/tanerdiler/microservice/order/repository/OrderRepository.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.order.repository;
2 |
3 | import com.tanerdiler.microservice.order.model.Order;
4 | import org.springframework.stereotype.Repository;
5 |
6 | import java.util.*;
7 |
8 | @Repository
9 | public class OrderRepository
10 | {
11 | private final static Map orders = new HashMap<>();
12 |
13 | static {
14 | new Order();
15 | orders.put(1, new Order(1,1,1, 1,10D, 5D));
16 | orders.put(2, new Order(2,2,1, 2,10D, 5D));
17 | orders.put(3, new Order(3,3,1, 1,10D, 5D));
18 | orders.put(4, new Order(4,4,1, 1,10D, 5D));
19 | orders.put(5, new Order(5,1,2, 5,10D, 5D));
20 | orders.put(6, new Order(6,2,2, 1,10D, 5D));
21 | orders.put(7, new Order(7,3,2, 8,10D, 5D));
22 | orders.put(8, new Order(8,4,2, 1,10D, 5D));
23 | orders.put(9, new Order(9,1,3, 4,10D, 5D));
24 | orders.put(10, new Order(10,2,3, 1,10D, 5D));
25 | orders.put(11, new Order(11,3,3, 8,10D, 5D));
26 | orders.put(12, new Order(12,4,3, 2,10D, 5D));
27 | orders.put(13, new Order(13,1,4, 1,10D, 5D));
28 | orders.put(14, new Order(14,2,4, 4,10D, 5D));
29 | orders.put(15, new Order(15,3,4, 3,10D, 5D));
30 | orders.put(16, new Order(16,4,4, 1,10D, 5D));
31 | }
32 |
33 | public Optional findById(Integer id)
34 | {
35 | return Optional.ofNullable(orders.get(id));
36 | }
37 |
38 | public Optional> findAll()
39 | {
40 | return Optional.ofNullable(orders.values());
41 | }
42 |
43 | public Order save(Order order)
44 | {
45 | Integer maxId = orders.keySet().stream().max(Integer::compareTo).get();
46 | return orders.put(maxId, order);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/java/com/tanerdiler/microservice/order/resource/OrderResource.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.order.resource;
2 |
3 | import static java.lang.String.format;
4 | import com.tanerdiler.microservice.order.model.Order;
5 | import com.tanerdiler.microservice.order.repository.OrderRepository;
6 | import lombok.RequiredArgsConstructor;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.http.ResponseEntity;
9 | import org.springframework.web.bind.annotation.*;
10 |
11 | import java.util.Collection;
12 | import java.util.Random;
13 |
14 | @Slf4j
15 | @RestController
16 | @RequestMapping("/api/v1/orders")
17 | @RequiredArgsConstructor
18 | public class OrderResource
19 | {
20 | private final OrderRepository repository;
21 | private final Random random = new Random();
22 |
23 | @GetMapping("/{id}")
24 | public ResponseEntity get(@PathVariable("id") Integer id)
25 | {
26 | // if (random.nextInt(100)<30) {
27 | // throw new RuntimeException(format("Product{%d} not found!", id));
28 | // }
29 | final var order = repository.findById(id).get();
30 | log.info("Order {} detail fetched {}", id, order);
31 | return ResponseEntity.ok(order);
32 | }
33 |
34 | @GetMapping()
35 | public ResponseEntity> getAll()
36 | {
37 | // if (random.nextInt(100)<30) {
38 | // throw new RuntimeException("Datasource not reached to fetch orders!");
39 | // }
40 | final var orders = repository.findAll().get();
41 | log.info("Executing fetching all orders {}", orders);
42 | return ResponseEntity.ok(orders);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: ${PORT:2222}
3 | servlet:
4 | context-path: /order
5 |
6 | spring:
7 | application:
8 | name: containerized-orders
9 | logstash:
10 | server: logstash
11 | port: 5000
12 | sleuth:
13 | traceId128: true
14 | supportsJoin: false
15 |
16 | management:
17 | endpoints:
18 | web:
19 | exposure:
20 | include: prometheus
21 | metrics:
22 | tags:
23 | application: app
24 | distribution:
25 | percentiles-histogram:
26 | http:
27 | server:
28 | requests: 'true'
29 | logging:
30 | pattern:
31 | level: "trace_id=%X{traceId:-} span_id=%X{spanId:-} trace_flags=%X{trace_flags} %p"
32 | level:
33 | com.tanerdiler.microservice.order: DEBUG
34 | org.springframework: WARN
35 | org.hibernate: WARN
36 |
37 | eureka:
38 | instance:
39 | prefer-ip-address: true
40 | client:
41 | serviceUrl:
42 | defaultZone: ${DISCOVERY_URL:http://discovery:8761}/eureka/
43 |
44 | ribbon:
45 | eureka:
46 | enabled: true
47 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ___ _ ____ _
2 | / _ \ _ __ __| | ___ _ __ / ___| ___ _ __ __ __ (_) ___ ___
3 | | | | | | '__| / _` | / _ \ | '__| \___ \ / _ \ | '__| \ \ / / | | / __| / _ \
4 | | |_| | | | | (_| | | __/ | | ___) | | __/ | | \ V / | | | (__ | __/
5 | \___/ |_| \__,_| \___| |_| |____/ \___| |_| \_/ |_| \___| \___|
6 |
--------------------------------------------------------------------------------
/containerized-orders/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ${LOG_FILE}
16 |
17 | ${FILE_LOG_PATTERN}
18 |
19 |
20 | ${LOG_FILE_ARCHIVE}-%d{yyyy-MM-dd}.%i.gz
21 | ${LOG_FILE_MAX_HISTORY:-0}
22 |
23 | ${LOG_FILE_MAX_SIZE:-10MB}
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | ${logstash-server:- }:${logstash-port:- }
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/containerized-orders/src/test/java/com/tanerdiler/microservice/order/ContainerizedOrdersApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.order;
2 |
3 |
4 | import org.junit.jupiter.api.Test;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 |
7 |
8 |
9 | @SpringBootTest
10 | public class ContainerizedOrdersApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/containerized-products/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/containerized-products/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-products/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/containerized-products/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/containerized-products/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:20.0.2_9-jre-alpine
2 | MAINTAINER Taner Diler
3 | ADD ./opentelemetry-javaagent.jar opentelemetry-javaagent.jar
4 | ADD target/containerized-products.jar containerized-products.jar
5 | ENTRYPOINT ["java", "-javaagent:/opentelemetry-javaagent.jar", "-jar", "/containerized-products.jar"]
6 | EXPOSE 2222
7 |
--------------------------------------------------------------------------------
/containerized-products/k8n/deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: k8n-service-products
5 | labels:
6 | app: k8n-service-products
7 | spec:
8 | replicas: 3
9 | selector:
10 | matchLabels:
11 | app: k8n-service-products
12 | template:
13 | metadata:
14 | labels:
15 | app: k8n-service-products
16 | spec:
17 | containers:
18 | - name: containerized-products
19 | image: tanerdiler/service-products-api:latest
20 | imagePullPolicy: Never
21 | ports:
22 | - containerPort: 2222
--------------------------------------------------------------------------------
/containerized-products/k8n/service.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: containerized-products
5 | spec:
6 | selector:
7 | app: k8n-service-products
8 | ports:
9 | - protocol: TCP
10 | port: 7501
11 | targetPort: 2222
--------------------------------------------------------------------------------
/containerized-products/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/containerized-products/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/containerized-products/opentelemetry-javaagent.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanerdiler/spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes/01dab0154a2a5000079227c38dcfc1436d83062f/containerized-products/opentelemetry-javaagent.jar
--------------------------------------------------------------------------------
/containerized-products/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.tanerdiler.microservice
7 | containerized-microservices
8 | 2.0.1
9 |
10 |
11 | containerized-products
12 | jar
13 |
14 | containerized-products
15 | Demo project for Spring Boot
16 |
17 |
18 |
19 | io.opentelemetry
20 | opentelemetry-bom
21 | 1.27.0
22 | pom
23 | import
24 |
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-actuator
36 |
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-netflix-eureka-client
41 |
42 |
43 |
44 |
45 | com.sun.jersey.contribs
46 | jersey-apache-client4
47 | 1.19.4
48 |
49 |
50 |
51 | io.micrometer
52 | micrometer-tracing-bridge-brave
53 |
54 |
55 | io.zipkin.reporter2
56 | zipkin-reporter-brave
57 |
58 |
59 | io.micrometer
60 | micrometer-registry-prometheus
61 |
62 |
63 | io.opentelemetry
64 | opentelemetry-api
65 |
66 |
67 | io.opentelemetry.javaagent
68 | opentelemetry-javaagent
69 | 1.27.0
70 |
71 |
72 |
73 |
74 | net.logstash.logback
75 | logstash-logback-encoder
76 | ${logtash-logback-encoder.version}
77 |
78 |
79 |
80 |
81 | org.springframework.boot
82 | spring-boot-starter-test
83 |
84 |
85 |
86 |
87 | org.projectlombok
88 | lombok
89 |
90 |
91 |
92 |
93 | containerized-products
94 |
95 |
96 | org.springframework.boot
97 | spring-boot-maven-plugin
98 |
99 |
100 | org.apache.maven.plugins
101 | maven-compiler-plugin
102 | ${maven.compiler.version}
103 |
104 | ${java.version}
105 |
106 |
107 | org.projectlombok
108 | lombok
109 | ${lombok.version}
110 |
111 |
112 | 19
113 | 19
114 |
115 |
116 |
117 | org.apache.maven.plugins
118 | maven-surefire-plugin
119 | ${maven.surefire.version}
120 |
121 |
122 | --illegal-access=permit
123 |
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-failsafe-plugin
129 | ${maven.surefire.version}
130 |
131 |
132 | --illegal-access=permit
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/containerized-products/src/main/java/com/tanerdiler/microservice/product/ContainerizedProductsApplication.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.product;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | @SpringBootApplication
8 | @EnableDiscoveryClient
9 | public class ContainerizedProductsApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ContainerizedProductsApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/containerized-products/src/main/java/com/tanerdiler/microservice/product/config/Config.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.product.config;
2 |
3 | import io.prometheus.client.exemplars.tracer.otel_agent.OpenTelemetryAgentSpanContextSupplier;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @Configuration
8 | public class Config {
9 | @Bean
10 | public OpenTelemetryAgentSpanContextSupplier openTelemetryAgentSpanContextSupplier() {
11 | return new OpenTelemetryAgentSpanContextSupplier();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/containerized-products/src/main/java/com/tanerdiler/microservice/product/model/Product.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.product.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class Product {
11 |
12 | private Integer id;
13 | private String name;
14 | private Double price;
15 | }
16 |
--------------------------------------------------------------------------------
/containerized-products/src/main/java/com/tanerdiler/microservice/product/repository/ProductRepository.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.product.repository;
2 |
3 | import com.tanerdiler.microservice.product.model.Product;
4 | import org.springframework.stereotype.Repository;
5 |
6 | import java.util.Collection;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 | import java.util.Optional;
10 |
11 | @Repository
12 | public class ProductRepository {
13 |
14 | private final static Map products = new HashMap<>();
15 |
16 | static {
17 | products.put(1, new Product(1, "5 saatlik şarj aleti", 100D));
18 | products.put(2, new Product(2, "traş makinası", 5D));
19 | products.put(3, new Product(3, "klavye", 200D));
20 | products.put(4, new Product(4, "sırt çantası", 50D));
21 | }
22 |
23 | public Optional findById(Integer id)
24 | {
25 | return Optional.ofNullable(products.get(id));
26 | }
27 |
28 | public Optional> findAll() {
29 | return Optional.ofNullable(products.values());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/containerized-products/src/main/java/com/tanerdiler/microservice/product/resource/ProductResource.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.product.resource;
2 |
3 | import static java.lang.String.format;
4 | import com.tanerdiler.microservice.product.model.Product;
5 | import com.tanerdiler.microservice.product.repository.ProductRepository;
6 | import lombok.RequiredArgsConstructor;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.slf4j.Logger;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.annotation.GetMapping;
11 | import org.springframework.web.bind.annotation.PathVariable;
12 | import org.springframework.web.bind.annotation.RequestMapping;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | import java.util.Collection;
16 | import java.util.Random;
17 |
18 | @Slf4j
19 | @RestController
20 | @RequestMapping("/api/v1/products")
21 | @RequiredArgsConstructor
22 | public class ProductResource {
23 |
24 | private final ProductRepository repository;
25 | private Random random = new Random();
26 |
27 | @GetMapping("/{id}")
28 | public ResponseEntity get(@PathVariable("id") Integer id)
29 | {
30 | // if (random.nextInt(100)<30) {
31 | // throw new RuntimeException(format("Product{%d} not found!", id));
32 | // }
33 | final var product = repository.findById(id).get();
34 | log.info("Product {} detail fetched {}", id, product);
35 | return ResponseEntity.ok(product);
36 | }
37 |
38 | @GetMapping()
39 | public ResponseEntity> getAll()
40 | {
41 | // if (random.nextInt(100)<30) {
42 | // throw new RuntimeException("Datasource not reached to fetch products!");
43 | // }
44 | final var products = repository.findAll().get();
45 | log.info("Executing fetching all products {}", products);
46 | return ResponseEntity.ok(products);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/containerized-products/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: ${PORT:2222}
3 | servlet:
4 | context-path: /product
5 |
6 | spring:
7 | application:
8 | name: containerized-products
9 | logging:
10 | pattern:
11 | level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"
12 | console: "%clr(%d{yyyy-MM-dd HH:mm:ss}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([${springAppName:-},%X{traceId:-},%X{spanId:-},%X{X-Span-Export:-}]){yellow} %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"
13 | level:
14 | org.springframework: WARN
15 | org.hibernate: WARN
16 | logstash:
17 | server: logstash
18 | port: 5000
19 | sleuth:
20 | traceId128: true
21 | supportsJoin: false
22 |
23 | management:
24 | endpoints:
25 | web:
26 | exposure:
27 | include: prometheus
28 | metrics:
29 | tags:
30 | application: app
31 | distribution:
32 | percentiles-histogram:
33 | http:
34 | server:
35 | requests: 'true'
36 | logging:
37 | pattern:
38 | level: "trace_id=%X{traceId:-} span_id=%X{spanId:-} trace_flags=%X{trace_flags} %p"
39 | level:
40 | com.tanerdiler.microservice.product: DEBUG
41 | org.springframework: WARN
42 | org.hibernate: WARN
43 |
44 | eureka:
45 | instance:
46 | prefer-ip-address: true
47 | client:
48 | register-with-eureka: true
49 | fetch-registry: true
50 | serviceUrl:
51 | defaultZone: ${DISCOVER_URL:http://discovery:8761}/eureka/
52 |
53 | ribbon:
54 | eureka:
55 | enabled: true
--------------------------------------------------------------------------------
/containerized-products/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ____ _ _ ____ _
2 | | _ \ _ __ ___ __| |_ _ ___| |_ / ___| ___ _ ____ _(_) ___ ___
3 | | |_) | '__/ _ \ / _` | | | |/ __| __| \___ \ / _ \ '__\ \ / / |/ __/ _ \
4 | | __/| | | (_) | (_| | |_| | (__| |_ ___) | __/ | \ V /| | (_| __/
5 | |_| |_| \___/ \__,_|\__,_|\___|\__| |____/ \___|_| \_/ |_|\___\___|
6 |
--------------------------------------------------------------------------------
/containerized-products/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ${LOG_FILE}
16 |
17 | ${FILE_LOG_PATTERN}
18 |
19 |
20 | ${LOG_FILE_ARCHIVE}-%d{yyyy-MM-dd}.%i.gz
21 | ${LOG_FILE_MAX_HISTORY:-0}
22 |
23 | ${LOG_FILE_MAX_SIZE:-10MB}
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | ${logstash-server:- }:${logstash-port:- }
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/containerized-products/src/test/java/com/tanerdiler/microservice/product/ContainerizedProductsApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.tanerdiler.microservice.product;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | public class ContainerizedProductsApplicationTests {
8 |
9 | @Test
10 | public void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/containerized-prometheus/config/prometheus.yml:
--------------------------------------------------------------------------------
1 | global:
2 | scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
3 | evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
4 | # scrape_timeout is set to the global default (10s).
5 |
6 | # Alertmanager configuration
7 | alerting:
8 | alertmanagers:
9 | - static_configs:
10 | - targets:
11 | # - alertmanager:9093
12 |
13 | # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
14 | rule_files:
15 | # - "first_rules.yml"
16 | # - "second_rules.yml"
17 |
18 | # A scrape configuration containing exactly one endpoint to scrape:
19 | # Here it's Prometheus itself.
20 | scrape_configs:
21 | - job_name: 'main'
22 | # Override the global default and scrape targets from this job every 5 seconds.
23 | metrics_path: '/backoffice/actuator/prometheus'
24 | scrape_interval: 5s
25 | static_configs:
26 | - targets: ['service-main:2222']
27 | - job_name: 'accounts'
28 | # Override the global default and scrape targets from this job every 5 seconds.
29 | metrics_path: '/account/actuator/prometheus'
30 | scrape_interval: 5s
31 | static_configs:
32 | - targets: ['service-accounts:2222']
33 | - job_name: 'products'
34 | # Override the global default and scrape targets from this job every 5 seconds.
35 | metrics_path: '/product/actuator/prometheus'
36 | scrape_interval: 5s
37 | static_configs:
38 | - targets: ['service-products:2222']
39 | - job_name: 'orders'
40 | # Override the global default and scrape targets from this job every 5 seconds.
41 | metrics_path: '/order/actuator/prometheus'
42 | scrape_interval: 5s
43 | static_configs:
44 | - targets: ['service-orders:2222']
45 | - job_name: 'discovery'
46 | # Override the global default and scrape targets from this job every 5 seconds.
47 | metrics_path: '/actuator/prometheus'
48 | scrape_interval: 5s
49 | static_configs:
50 | - targets: ['discovery:8761']
51 | - job_name: 'gateway'
52 | # Override the global default and scrape targets from this job every 5 seconds.
53 | metrics_path: '/actuator/prometheus'
54 | scrape_interval: 5s
55 | static_configs:
56 | - targets: ['gateway:8762']
57 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | x-logging: &default-logging
2 | driver: loki
3 | options:
4 | loki-url: 'http://localhost:3100/api/prom/push'
5 | loki-pipeline-stages: |
6 | - multiline:
7 | firstline: '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}'
8 | max_wait_time: 3s
9 | - regex:
10 | expression: '^(?P\d{4}-\d{2}-\d{2}) (?P