mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-11-18 20:07:12 +00:00
spring-36-37 spring-cloud
This commit is contained in:
1 parent
b9326e0e4b
commit
3209f1cc8a
74 files changed
+5204
No files matched your search
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Whitespace-only changes.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Whitespace-only changes.
BIN
Binary file not shown.
+2
@@ -0,0 +1,2 @@
|
||||
#Sun Oct 06 17:31:48 MSK 2024
|
||||
gradle.version=8.10.2
|
||||
BIN
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
Executable
+1
@@ -0,0 +1 @@
|
||||
# Spring Cloud example
|
||||
@@ -0,0 +1,14 @@
|
||||
dependencies {
|
||||
implementation(project(":kafka-log-appender"))
|
||||
implementation("net.logstash.logback:logstash-logback-encoder")
|
||||
implementation("ch.qos.logback:logback-classic")
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
implementation("io.micrometer:micrometer-registry-prometheus")
|
||||
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-gateway")
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
|
||||
|
||||
implementation("io.micrometer:micrometer-tracing-bridge-otel") // bridges the Micrometer Observation API to OpenTelemetry.
|
||||
implementation("io.opentelemetry:opentelemetry-exporter-zipkin") // reports traces to Zipkin.
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+52
@@ -0,0 +1,52 @@
|
||||
spring:
|
||||
application:
|
||||
name: api-gateway
|
||||
|
||||
|
||||
server:
|
||||
port: 7777
|
||||
|
||||
application:
|
||||
api-routes:
|
||||
- id: "service-client"
|
||||
from: "client"
|
||||
to: "lb://SERVICE-CLIENT"
|
||||
- id: "service-order"
|
||||
from: "order"
|
||||
to: "lb://SERVICE-ORDER"
|
||||
|
||||
eureka:
|
||||
client:
|
||||
registerWithEureka: false
|
||||
fetchRegistry: true
|
||||
serviceUrl:
|
||||
defaultZone: http://localhost:9999/eureka/
|
||||
instance:
|
||||
lease-renewal-interval-in-seconds: 30
|
||||
metadataMap:
|
||||
zone: zone1
|
||||
|
||||
management:
|
||||
tracing:
|
||||
sampling:
|
||||
probability: 1.0
|
||||
endpoint:
|
||||
prometheus:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
probes:
|
||||
enabled: true
|
||||
refresh:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- prometheus
|
||||
- health
|
||||
- metrics
|
||||
- refresh
|
||||
enabled-by-default: false
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<jmxConfigurator />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="kafka" class="ru.appender.kafka.LogAppender">
|
||||
<bootstrapServers>localhost:9092</bootstrapServers>
|
||||
<topicName>applLogs</topicName>
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<fieldNames>
|
||||
<version>[ignore]</version>
|
||||
</fieldNames>
|
||||
<customFields>{"appname":"api-gateway"}</customFields>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="kafka" />
|
||||
</root>
|
||||
</configuration>
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
./hey -n=1000000 -c=1 -m GET http://localhost:7777/client/info?name=testClientName
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package ru.demo;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ApiGateway {
|
||||
private static final Logger log = LoggerFactory.getLogger(ApiGateway.class);
|
||||
|
||||
/*
|
||||
curl -v http://localhost:7777/client/info?name=testClientName
|
||||
curl -v http://localhost:7777/order/info?id=testOrderId
|
||||
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ApiGateway.class, args);
|
||||
log.info("SrvApiGateway started");
|
||||
}
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
package ru.demo.config;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.demo.controller.XrequestFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ApplConfigProperties.class)
|
||||
@EnableDiscoveryClient
|
||||
public class ApiConfig {
|
||||
|
||||
@Bean
|
||||
public XrequestFilter xrequestFilter() {
|
||||
return new XrequestFilter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
RouteLocator gateway(
|
||||
RouteLocatorBuilder rlb, ApplConfigProperties applConfigProperties, XrequestFilter xrequestFilter) {
|
||||
var routesBuilder = rlb.routes();
|
||||
for (var route : applConfigProperties.getApiRoutes()) {
|
||||
routesBuilder.route(route.id(), routeSpec -> routeSpec
|
||||
.path(String.format("/%s/**", route.from()))
|
||||
.filters(fs -> fs.filters(xrequestFilter)
|
||||
.rewritePath(String.format("/%s/(?<segment>.*)", route.from()), "/${segment}"))
|
||||
.uri(String.format("%s/@", route.to())));
|
||||
}
|
||||
return routesBuilder.build();
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package ru.demo.config;
|
||||
|
||||
public record ApiRoute(String id, String from, String to) {}
|
||||
2024-07/spring-36-37-spring-cloud/api-gateway/src/main/java/ru/demo/config/ApplConfigProperties.java
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package ru.demo.config;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
|
||||
@ConfigurationProperties(prefix = "application")
|
||||
public class ApplConfigProperties {
|
||||
private final String authHost;
|
||||
private final List<ApiRoute> apiRoutes;
|
||||
|
||||
@ConstructorBinding
|
||||
public ApplConfigProperties(String authHost, List<ApiRoute> apiRoutes) {
|
||||
this.authHost = authHost;
|
||||
this.apiRoutes = apiRoutes;
|
||||
}
|
||||
|
||||
public String getAuthHost() {
|
||||
return authHost;
|
||||
}
|
||||
|
||||
public List<ApiRoute> getApiRoutes() {
|
||||
return apiRoutes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ApplConfigProperties{" + "authHost='" + authHost + '\'' + ", apiRoutes=" + apiRoutes + '}';
|
||||
}
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
package ru.demo.controller;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.annotation.NonNull;
|
||||
|
||||
@Order(-2)
|
||||
@Component
|
||||
public class ErrorHandler implements ErrorWebExceptionHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(ErrorHandler.class);
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(@NonNull ServerWebExchange serverWebExchange, @NonNull Throwable thr) {
|
||||
var bufferFactory = serverWebExchange.getResponse().bufferFactory();
|
||||
var response = serverWebExchange.getResponse();
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
if (thr instanceof ConnectException) {
|
||||
log.error("Target host connection error", thr);
|
||||
response.setStatusCode(HttpStatus.SERVICE_UNAVAILABLE);
|
||||
var dataBuffer = bufferFactory.wrap("Target host connection error".getBytes());
|
||||
return response.writeWith(Mono.just(dataBuffer));
|
||||
} else {
|
||||
log.error("Unhandled exception", thr);
|
||||
response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
var dataBuffer = bufferFactory.wrap("Unhandled error".getBytes());
|
||||
return response.writeWith(Mono.just(dataBuffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
package ru.demo.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class XrequestFilter implements GatewayFilter {
|
||||
private static final String HEADER_X_REQUEST_ID = "X-Request-Id";
|
||||
private static final Logger log = LoggerFactory.getLogger(XrequestFilter.class);
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
var guid = java.util.UUID.randomUUID().toString();
|
||||
log.info("requestId:{}", guid);
|
||||
|
||||
var request =
|
||||
exchange.getRequest().mutate().header(HEADER_X_REQUEST_ID, guid).build();
|
||||
|
||||
return chain.filter(exchange.mutate().request(request).build());
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
spring:
|
||||
application:
|
||||
name: api-gateway
|
||||
|
||||
|
||||
server:
|
||||
port: 7777
|
||||
|
||||
application:
|
||||
api-routes:
|
||||
- id: "service-client"
|
||||
from: "client"
|
||||
to: "lb://SERVICE-CLIENT"
|
||||
- id: "service-order"
|
||||
from: "order"
|
||||
to: "lb://SERVICE-ORDER"
|
||||
|
||||
eureka:
|
||||
client:
|
||||
registerWithEureka: false
|
||||
fetchRegistry: true
|
||||
serviceUrl:
|
||||
defaultZone: http://localhost:9999/eureka/
|
||||
instance:
|
||||
lease-renewal-interval-in-seconds: 30
|
||||
metadataMap:
|
||||
zone: zone1
|
||||
|
||||
management:
|
||||
tracing:
|
||||
sampling:
|
||||
probability: 1.0
|
||||
endpoint:
|
||||
prometheus:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
probes:
|
||||
enabled: true
|
||||
refresh:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- prometheus
|
||||
- health
|
||||
- metrics
|
||||
- refresh
|
||||
enabled-by-default: false
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<jmxConfigurator />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="kafka" class="ru.appender.kafka.LogAppender">
|
||||
<bootstrapServers>localhost:9092</bootstrapServers>
|
||||
<topicName>applLogs</topicName>
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<fieldNames>
|
||||
<version>[ignore]</version>
|
||||
</fieldNames>
|
||||
<customFields>{"appname":"api-gateway"}</customFields>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="kafka" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,12 @@
|
||||
dependencies {
|
||||
implementation(project(":kafka-log-appender"))
|
||||
implementation("net.logstash.logback:logstash-logback-encoder")
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
implementation("io.micrometer:micrometer-registry-prometheus")
|
||||
|
||||
implementation ("org.springframework.cloud:spring-cloud-config-server")
|
||||
|
||||
implementation("io.micrometer:micrometer-tracing-bridge-otel") // bridges the Micrometer Observation API to OpenTelemetry.
|
||||
implementation("io.opentelemetry:opentelemetry-exporter-zipkin") // reports traces to Zipkin.
|
||||
}
|
||||
BIN
Binary file not shown.
+38
@@ -0,0 +1,38 @@
|
||||
server:
|
||||
port: 8888
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: config-server
|
||||
cloud:
|
||||
config:
|
||||
server:
|
||||
git:
|
||||
uri: "git@github.com:petrelevich/jvm-digging.git"
|
||||
search-paths: "spring-cloud/git-config"
|
||||
ignoreLocalSshSettings: false
|
||||
strictHostKeyChecking: false
|
||||
management:
|
||||
tracing:
|
||||
sampling:
|
||||
probability: 1.0
|
||||
endpoint:
|
||||
prometheus:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
probes:
|
||||
enabled: true
|
||||
refresh:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- prometheus
|
||||
- health
|
||||
- metrics
|
||||
- refresh
|
||||
enabled-by-default: false
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<jmxConfigurator />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="kafka" class="ru.appender.kafka.LogAppender">
|
||||
<bootstrapServers>localhost:9092</bootstrapServers>
|
||||
<topicName>applLogs</topicName>
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<fieldNames>
|
||||
<version>[ignore]</version>
|
||||
</fieldNames>
|
||||
<customFields>{"appname":"config-server"}</customFields>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="kafka" />
|
||||
</root>
|
||||
</configuration>
|
||||
BIN
Binary file not shown.
+19
@@ -0,0 +1,19 @@
|
||||
package ru.demo;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.config.server.EnableConfigServer;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableConfigServer
|
||||
public class ConfigServer {
|
||||
private static final Logger log = LoggerFactory.getLogger(ConfigServer.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(ConfigServer.class, args);
|
||||
log.info("ConfigServer started");
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
server:
|
||||
port: 8888
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: config-server
|
||||
cloud:
|
||||
config:
|
||||
server:
|
||||
git:
|
||||
uri: "git@github.com:petrelevich/jvm-digging.git"
|
||||
search-paths: "spring-cloud/git-config"
|
||||
ignoreLocalSshSettings: false
|
||||
strictHostKeyChecking: false
|
||||
management:
|
||||
tracing:
|
||||
sampling:
|
||||
probability: 1.0
|
||||
endpoint:
|
||||
prometheus:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
probes:
|
||||
enabled: true
|
||||
refresh:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- prometheus
|
||||
- health
|
||||
- metrics
|
||||
- refresh
|
||||
enabled-by-default: false
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<jmxConfigurator />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="kafka" class="ru.appender.kafka.LogAppender">
|
||||
<bootstrapServers>localhost:9092</bootstrapServers>
|
||||
<topicName>applLogs</topicName>
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<fieldNames>
|
||||
<version>[ignore]</version>
|
||||
</fieldNames>
|
||||
<customFields>{"appname":"config-server"}</customFields>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="kafka" />
|
||||
</root>
|
||||
</configuration>
|
||||
File diff suppressed because it is too large.
Load diff
+143
@@ -0,0 +1,143 @@
|
||||
|
||||
services:
|
||||
opensearch-node1:
|
||||
image: opensearchproject/opensearch:2.18.0
|
||||
container_name: opensearch-node1
|
||||
environment:
|
||||
- cluster.name=opensearch-cluster # Name the cluster
|
||||
- node.name=opensearch-node1 # Name the node that will run in this container
|
||||
- discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
|
||||
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligibile to serve as cluster manager
|
||||
- bootstrap.memory_lock=true # Disable JVM heap memory swapping
|
||||
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
|
||||
- "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch
|
||||
- "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin
|
||||
ulimits:
|
||||
memlock:
|
||||
soft: -1 # Set memlock to unlimited (no soft or hard limit)
|
||||
hard: -1
|
||||
nofile:
|
||||
soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
|
||||
hard: 65536
|
||||
volumes:
|
||||
- opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container
|
||||
ports:
|
||||
- 9200:9200 # REST API
|
||||
- 9600:9600 # Performance Analyzer
|
||||
networks:
|
||||
- opensearch-net # All of the containers will join the same Docker bridge network
|
||||
opensearch-node2:
|
||||
image: opensearchproject/opensearch:2.18.0
|
||||
container_name: opensearch-node2
|
||||
environment:
|
||||
- cluster.name=opensearch-cluster # Name the cluster
|
||||
- node.name=opensearch-node2 # Name the node that will run in this container
|
||||
- discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
|
||||
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligibile to serve as cluster manager
|
||||
- bootstrap.memory_lock=true # Disable JVM heap memory swapping
|
||||
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
|
||||
- "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch
|
||||
- "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin
|
||||
ulimits:
|
||||
memlock:
|
||||
soft: -1 # Set memlock to unlimited (no soft or hard limit)
|
||||
hard: -1
|
||||
nofile:
|
||||
soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
|
||||
hard: 65536
|
||||
volumes:
|
||||
- opensearch-data2:/usr/share/opensearch/data # Creates volume called opensearch-data2 and mounts it to the container
|
||||
networks:
|
||||
- opensearch-net # All of the containers will join the same Docker bridge network
|
||||
opensearch-dashboards:
|
||||
image: opensearchproject/opensearch-dashboards:2.18.0
|
||||
container_name: opensearch-dashboards
|
||||
ports:
|
||||
- 5601:5601 # Map host port 5601 to container port 5601
|
||||
expose:
|
||||
- "5601" # Expose port 5601 for web access to OpenSearch Dashboards
|
||||
environment:
|
||||
- 'OPENSEARCH_HOSTS=["http://opensearch-node1:9200","http://opensearch-node2:9200"]'
|
||||
- "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true" # disables security dashboards plugin in OpenSearch Dashboards
|
||||
networks:
|
||||
- opensearch-net
|
||||
|
||||
#logstash
|
||||
|
||||
logstash:
|
||||
image: opensearchproject/logstash-oss-with-opensearch-output-plugin:7.16.2
|
||||
container_name: logstash
|
||||
volumes:
|
||||
- ./logstash.conf:/usr/share/logstash/pipeline/logstash.conf
|
||||
networks:
|
||||
- opensearch-net
|
||||
|
||||
zookeeper:
|
||||
image: confluentinc/cp-zookeeper:6.2.0
|
||||
container_name: zookeeper
|
||||
environment:
|
||||
ZOOKEEPER_CLIENT_PORT: 2181
|
||||
ZOOKEEPER_TICK_TIME: 2000
|
||||
networks:
|
||||
- opensearch-net
|
||||
|
||||
broker:
|
||||
image: confluentinc/cp-kafka:7.0.0
|
||||
container_name: broker
|
||||
ports:
|
||||
- "9092:9092"
|
||||
depends_on:
|
||||
- zookeeper
|
||||
environment:
|
||||
KAFKA_BROKER_ID: 1
|
||||
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
|
||||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT
|
||||
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092
|
||||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
||||
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
|
||||
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
|
||||
networks:
|
||||
- opensearch-net
|
||||
|
||||
kafka-ui:
|
||||
container_name: kafka-ui
|
||||
image: provectuslabs/kafka-ui:latest
|
||||
network_mode: "host"
|
||||
environment:
|
||||
DYNAMIC_CONFIG_ENABLED: 'true'
|
||||
|
||||
zipkin:
|
||||
container_name: zipkin
|
||||
image: openzipkin/zipkin:3
|
||||
network_mode: "host"
|
||||
expose:
|
||||
- "9411"
|
||||
|
||||
prometheus:
|
||||
image: bitnami/prometheus:3.0.1
|
||||
container_name: prometheus
|
||||
network_mode: "host"
|
||||
expose:
|
||||
- "9090"
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./prometheus.yml
|
||||
target: /etc/prometheus/prometheus.yml
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana-enterprise:11.4.0
|
||||
container_name: grafana
|
||||
network_mode: "host"
|
||||
expose:
|
||||
- "3000"
|
||||
environment:
|
||||
GF_SECURITY_ADMIN_USER: "grafana"
|
||||
GF_SECURITY_ADMIN_PASSWORD: "grafana"
|
||||
|
||||
|
||||
volumes:
|
||||
opensearch-data1:
|
||||
opensearch-data2:
|
||||
|
||||
networks:
|
||||
opensearch-net:
|
||||
@@ -0,0 +1,24 @@
|
||||
input {
|
||||
http {
|
||||
id => "test_http_plugin_id"
|
||||
host => "127.0.0.1"
|
||||
port => 8080
|
||||
}
|
||||
|
||||
kafka {
|
||||
bootstrap_servers => "broker:29092"
|
||||
topics => "applLogs"
|
||||
codec => "json"
|
||||
}
|
||||
}
|
||||
|
||||
output {
|
||||
opensearch {
|
||||
hosts => "http://opensearch-node1:9200"
|
||||
user => "admin"
|
||||
password => "admin"
|
||||
index => "logstash-logs-%{+YYYY.MM.dd}"
|
||||
ssl_certificate_verification => false
|
||||
ssl => false
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
# JVM (Micrometer) Grafana dashboard: 4701
|
||||
global:
|
||||
scrape_interval: 10s
|
||||
evaluation_interval: 15s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: service-client
|
||||
metrics_path: '/actuator/prometheus'
|
||||
scrape_interval: 5s
|
||||
static_configs:
|
||||
- targets: ['localhost:8081']
|
||||
@@ -0,0 +1,13 @@
|
||||
dependencies {
|
||||
implementation(project(":kafka-log-appender"))
|
||||
implementation("net.logstash.logback:logstash-logback-encoder")
|
||||
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
implementation("io.micrometer:micrometer-registry-prometheus")
|
||||
|
||||
implementation ("org.springframework.cloud:spring-cloud-config-server")
|
||||
implementation ("org.springframework.cloud:spring-cloud-starter-netflix-eureka-server")
|
||||
|
||||
implementation("io.micrometer:micrometer-tracing-bridge-otel") // bridges the Micrometer Observation API to OpenTelemetry.
|
||||
implementation("io.opentelemetry:opentelemetry-exporter-zipkin") // reports traces to Zipkin.
|
||||
}
|
||||
BIN
Binary file not shown.
+42
@@ -0,0 +1,42 @@
|
||||
spring:
|
||||
application:
|
||||
name: eureka-server
|
||||
server:
|
||||
port: 9999
|
||||
|
||||
eureka:
|
||||
server:
|
||||
renewal-percent-threshold: 0.5
|
||||
instance:
|
||||
hostname: localhost
|
||||
lease-expiration-duration-in-seconds: 90
|
||||
client:
|
||||
registerWithEureka: false
|
||||
fetchRegistry: false
|
||||
serviceUrl:
|
||||
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
|
||||
|
||||
management:
|
||||
tracing:
|
||||
sampling:
|
||||
probability: 1.0
|
||||
endpoint:
|
||||
prometheus:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
probes:
|
||||
enabled: true
|
||||
refresh:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- prometheus
|
||||
- health
|
||||
- metrics
|
||||
- refresh
|
||||
enabled-by-default: false
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<jmxConfigurator />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="kafka" class="ru.appender.kafka.LogAppender">
|
||||
<bootstrapServers>localhost:9092</bootstrapServers>
|
||||
<topicName>applLogs</topicName>
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<fieldNames>
|
||||
<version>[ignore]</version>
|
||||
</fieldNames>
|
||||
<customFields>{"appname":"eureka-server"}</customFields>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="kafka" />
|
||||
</root>
|
||||
</configuration>
|
||||
BIN
Binary file not shown.
+19
@@ -0,0 +1,19 @@
|
||||
package ru.demo;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaServer
|
||||
public class EurekaServer {
|
||||
private static final Logger log = LoggerFactory.getLogger(EurekaServer.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(EurekaServer.class, args);
|
||||
log.info("EurekaServer started");
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
spring:
|
||||
application:
|
||||
name: eureka-server
|
||||
server:
|
||||
port: 9999
|
||||
|
||||
eureka:
|
||||
server:
|
||||
renewal-percent-threshold: 0.5
|
||||
instance:
|
||||
hostname: localhost
|
||||
lease-expiration-duration-in-seconds: 90
|
||||
client:
|
||||
registerWithEureka: false
|
||||
fetchRegistry: false
|
||||
serviceUrl:
|
||||
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
|
||||
|
||||
management:
|
||||
tracing:
|
||||
sampling:
|
||||
probability: 1.0
|
||||
endpoint:
|
||||
prometheus:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
probes:
|
||||
enabled: true
|
||||
refresh:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- prometheus
|
||||
- health
|
||||
- metrics
|
||||
- refresh
|
||||
enabled-by-default: false
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<jmxConfigurator />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="kafka" class="ru.appender.kafka.LogAppender">
|
||||
<bootstrapServers>localhost:9092</bootstrapServers>
|
||||
<topicName>applLogs</topicName>
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<fieldNames>
|
||||
<version>[ignore]</version>
|
||||
</fieldNames>
|
||||
<customFields>{"appname":"eureka-server"}</customFields>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="kafka" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,28 @@
|
||||
management:
|
||||
tracing:
|
||||
sampling:
|
||||
probability: 1.0
|
||||
endpoint:
|
||||
prometheus:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
health:
|
||||
enabled: true
|
||||
probes:
|
||||
enabled: true
|
||||
refresh:
|
||||
enabled: true
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include:
|
||||
- prometheus
|
||||
- health
|
||||
- metrics
|
||||
- refresh
|
||||
enabled-by-default: false
|
||||
metrics:
|
||||
tags:
|
||||
application: ${spring.application.name}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 8083
|
||||
@@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 8081
|
||||
@@ -0,0 +1,2 @@
|
||||
server:
|
||||
port: 8082
|
||||
BIN
Binary file not shown.
+7
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
+249
@@ -0,0 +1,249 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package ru.demo;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.demo.controller.InstanceId;
|
||||
|
||||
@Configuration
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
InstanceId instanceId(@Value("${spring.application.instance_id}") String id) {
|
||||
return new InstanceId(id);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package ru.demo;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ServiceOrder {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder().sources(ServiceOrder.class).run(args);
|
||||
}
|
||||
}
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
package ru.demo.controller;
|
||||
|
||||
public record InstanceId(String name) {}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package ru.demo.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class OrderController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderController.class);
|
||||
private final InstanceId instanceId;
|
||||
|
||||
public OrderController(InstanceId instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
// curl -v http://localhost:8082/info?id="idClient"
|
||||
|
||||
// curl -v http://localhost:8091/info?id="idClient"
|
||||
// curl -v http://localhost:8092/info?id="idClient"
|
||||
|
||||
@GetMapping(value = "/info")
|
||||
public String info(@RequestParam(name = "id") String id) {
|
||||
logger.info("instanceId:{}, request. id:{}", instanceId.name(), id);
|
||||
return String.format("%s, Order id:%s", instanceId.name(), id);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
spring:
|
||||
application:
|
||||
name: service-order
|
||||
instance_id: i0
|
||||
cloud:
|
||||
config:
|
||||
fail-fast: true
|
||||
retry:
|
||||
initial-interval: 5000
|
||||
max-attempts: 10
|
||||
max-interval: 5000
|
||||
multiplier: 1.2
|
||||
config:
|
||||
import: optional:configserver:http://localhost:8888
|
||||
codec:
|
||||
max-in-memory-size: 10MB
|
||||
|
||||
eureka:
|
||||
client:
|
||||
fetchRegistry: false
|
||||
serviceUrl:
|
||||
defaultZone: http://localhost:9999/eureka/
|
||||
instance:
|
||||
instance-id: service-order:${spring.application.instance_id:0}
|
||||
lease-renewal-interval-in-seconds: 30
|
||||
metadataMap:
|
||||
zone: zone1
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<jmxConfigurator />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - [%X{requestId}] %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="kafka" class="ru.appender.kafka.LogAppender">
|
||||
<bootstrapServers>localhost:9092</bootstrapServers>
|
||||
<topicName>applLogs</topicName>
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<fieldNames>
|
||||
<version>[ignore]</version>
|
||||
</fieldNames>
|
||||
<customFields>{"appname":"service-order"}</customFields>
|
||||
<includeMdcKeyName>requestId</includeMdcKeyName>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="kafka" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in new issue
Block a user