This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-samples.git
The following commit(s) were added to refs/heads/main by this push:
new 76ee2b4 Migrate Spring Cloud Sample Application
76ee2b4 is described below
commit 76ee2b47ad33ac49a5cbc8fed2f665dad82ce6f0
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Fri Feb 17 23:49:44 2023 +0100
Migrate Spring Cloud Sample Application
---
.github/dependabot.yaml | 3 +
.../Dockerfile | 32 ++++
.../README.md | 55 ++++++
.../docker/app-compose.yml | 21 +++
.../docker/combined-compose.yml | 86 +++++++++
.../docker/docker-compose.yml | 74 ++++++++
.../docker/down.sh | 24 +++
.../docker/init/fluent-bit/fluent-bit.conf | 28 +++
.../docker/init/flume/flume-env.sh | 19 ++
.../docker/init/flume/flume.conf | 48 +++++
.../docker/init/flume/log4j.properties | 25 +++
.../docker/init/flume/start-flume.sh | 33 ++++
.../docker/init/rabbit/definitions.json | 36 ++++
.../docker/init/rabbit/rabbitmq.config | 14 ++
.../docker/logs.sh | 26 +++
.../docker/restartApp.sh | 39 ++++
.../docker/stop.sh | 25 +++
.../docker/stopApp.sh | 22 +++
.../docker/up.sh | 25 +++
.../k8s/deploy.sh | 36 ++++
.../k8s/sampleapp-deployment.yaml | 53 ++++++
.../k8s/undeploy.sh | 29 +++
.../pom.xml | 202 +++++++++++++++++++++
.../cloud/config/sample/SampleApplication.java | 29 +++
.../sample/config/GlobalExceptionHandler.java | 37 ++++
.../cloud/config/sample/config/WebMvcConfig.java | 40 ++++
.../config/sample/controller/K8SController.java | 81 +++++++++
.../config/sample/controller/SampleController.java | 118 ++++++++++++
.../utils/spring/SampleResponseErrorHandler.java | 36 ++++
.../src/main/resources/META-INF/MANIFEST.MF | 0
.../src/main/resources/application.yml | 33 ++++
.../src/main/resources/bootstrap.yml | 5 +
.../src/main/resources/log4j2.component.properties | 19 ++
pom.xml | 28 ++-
34 files changed, 1380 insertions(+), 1 deletion(-)
diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml
index c22403c..a2990e6 100644
--- a/.github/dependabot.yaml
+++ b/.github/dependabot.yaml
@@ -24,6 +24,9 @@ updates:
# Version 3.x uses Jakarta EE 9 and Java 17
- dependency-name: "org.springframework.boot:spring-boot-starter-parent"
update-types: ["version-update:semver-major"]
+ # Version 2022.x uses Jakarta EE 9 and Java 17
+ - dependency-name: "org.springframework.cloud:spring-cloud-dependencies"
+ update-types: ["version-update:semver-major"]
# Version 11.x uses Jakarta EE 9
- dependency-name: "org.eclipse.jetty:jetty-maven-plugin"
update-types: ["version-update:semver-major"]
diff --git a/log4j-spring-cloud-config-sample-application/Dockerfile
b/log4j-spring-cloud-config-sample-application/Dockerfile
new file mode 100644
index 0000000..ce218d3
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/Dockerfile
@@ -0,0 +1,32 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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
+#
+# http://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.
+#
+# Alpine Linux with OpenJDK
+#FROM openjdk:8-jdk-alpine
+FROM openjdk:11-jdk-slim
+
+ARG build_version
+ENV BUILD_VERSION=${build_version}
+RUN mkdir /service
+
+ADD ./target/sampleapp.jar /service/
+WORKDIR /service
+
+#EXPOSE 8080 5005
+EXPOSE 8080
+
+#CMD java
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005" -jar
sampleapp.jar
+ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar -Xmx1G sampleapp.jar"]
diff --git a/log4j-spring-cloud-config-sample-application/README.md
b/log4j-spring-cloud-config-sample-application/README.md
new file mode 100644
index 0000000..686be3a
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/README.md
@@ -0,0 +1,55 @@
+# Log4j Spring Cloud Sample Application
+
+This application uses Spring Boot and reads the logging configuration from the
companion Spring Cloud Config Server
+project. The log4j2.xml file is located in the config-repo directory in that
project.
+
+## Running With Docker
+This sample packages the application in a docker container that is packaged
with rabbit-mq (to allow dynamic updates
+from Spring Cloud Config), fluent-bit (to test as a log forwarder), Apache
Flume (to test as a log forwarder), and
+Apache Kafka also as a log forwarder. It also installs Socat, a proxy to allow
access to the Docker REST API.
+###Prerequisites
+Note: This guide assumes you already have docker installed. If you do not you
may either use homebrew to install
+it or follow the instructions at
https://docs.docker.com/docker-for-mac/install/.
+
+Like Log4j, the sample app uses the Maven toolchains plugin. The sample app
may be built with Java 8 but is
+configured to run in a docker container with Java 11.
+
+The KafkaAppender requires a Kafka instance to write to. On MacOS a Kafka
instance can be created by
+```
+brew install kafka
+zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties &
kafka-server-start /usr/local/etc/kafka/server.properties
+```
+
+### Starting the Application
+* Start the companion rabbit-mq, fluent-bit and flume images `./docker/up.sh`
+* Compile and start local application image `./docker/restartApp.sh`
+* The application exposes two endpoints.
+ 1. http://localhost:8080/sample/log?threads=1&count=100000 This endpoint
will log up to 100,000 events using
+ 1 or more threads.
+ 1. http://localhost:8080/sample/exception This endpoint generates an
exception that can be used to verify whether
+ multiline logging works with the chosen set of components.
+
+### Viewing the logs
+
+Accessing the log files varies depending on the appending being used. When
logging to the console "docker logs" may
+be used. As configured, Flume will write to files in /var/log/flume,
fluent-bit to the standard output of its container.
+Kafka output may be viewed using a tool like [Kafka
Tool](http://www.kafkatool.com/).
+
+## Running with Kubernetes
+
+This sample has been verified to run in a Docker Desktop for Mac environment
with Kubernetes enabled and may run in
+other Kubernetes environments.
+
+### Prerequisites
+Note: This guide assumes you already have Docker and Kubernetes installed.
Since the same container is used for
+Kubernetes as with Docker, Java 11 is also required. This implmentation uses
an ELK stack which is expected to
+be installed. They can be downloaded individually and started as local
applications on the development
+machine for testing. Logstash should be configured as shown in
+[Logging in the Cloud](http://logging.apache.org/log4j/2.x/manual/cloud.html).
+
+### Starting the Application
+Run the ```docker/deploy.sh``` command from the base directory of the
log4j-spring-cloud-config-sample-application
+project. This will build the application and then deploy it to Kubernetes. You
should see the start-up logs in Kibana.
+To stop, run the ```docker/undeploy.sh``` script, then run ```docker images```
and perform
+```docker rmi --force {image id}``` where image id is the id of the image for
the sample application.
+
diff --git
a/log4j-spring-cloud-config-sample-application/docker/app-compose.yml
b/log4j-spring-cloud-config-sample-application/docker/app-compose.yml
new file mode 100755
index 0000000..9864e8e
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/app-compose.yml
@@ -0,0 +1,21 @@
+version: "3"
+services:
+ sampleapp:
+ container_name: sampleapp
+ image: sampleapp
+ environment:
+ DOCKER_URI: http://socat:1234
+ SERVICE_PARAMS:
--spring.config.location=classpath:/,classpath:/application-local-docker.yml
+ ports:
+ - "5005:5005"
+ - "8080:8080"
+ networks:
+ sample_network:
+ aliases:
+ - sampleapp
+
+networks:
+ sample_network:
+
+volumes:
+ pgdata:
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/combined-compose.yml
b/log4j-spring-cloud-config-sample-application/docker/combined-compose.yml
new file mode 100755
index 0000000..b2f5abb
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/combined-compose.yml
@@ -0,0 +1,86 @@
+version: "3"
+services:
+ socat:
+ container_name: socat
+ image: bobrik/socat
+ command: TCP-LISTEN:1234,fork UNIX-CONNECT:/var/run/docker.sock
+ expose:
+ - "1234"
+ volumes:
+ - /var/run/docker.sock:/var/run/docker.sock
+ networks:
+ sample_network:
+ aliases:
+ - socat
+
+ rabbitmq:
+ container_name: rabbit
+ image: rabbitmq:3-management-alpine
+ expose:
+ - "5672"
+ - "15672"
+ ports:
+ - "5672:5672"
+ - "15672:15672"
+ volumes:
+ - ./init/rabbit/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
+ - ./init/rabbit/definitions.json:/etc/rabbitmq/definitions.json:ro
+ networks:
+ sample_network:
+ aliases:
+ - rabbitmq
+
+ fluent-bit:
+ container_name: fluent-bit
+ image: fluent/fluent-bit:latest
+ expose:
+ - "2020"
+ - "24221"
+ - "24224"
+ ports:
+ - "24224:24224"
+ volumes:
+ - ./init/fluent-bit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
+ - ./target/logs:/var/logs
+ networks:
+ sample_network:
+ aliases:
+ - fluent-bit
+
+ flume:
+ container_name: flume
+ image: probablyfine/flume:latest
+ expose:
+ - "5050"
+ environment:
+ FLUME_AGENT_NAME: forwarder
+ FLUME_JAVA_OPTS:
-Dlog4j.configuration=file:///opt/flume-config/log4j.properties
+ volumes:
+ - ./init/flume/start-flume.sh:/opt/flume/bin/start-flume
+ - ./init/flume/flume.conf:/opt/flume-config/flume.conf
+ - ./init/flume/flume-env.sh:/opt/flume-config/flume-env.sh
+ - ./init/flume/log4j.properties:/opt/flume-config/log4j.properties
+ - ~/flume-logs:/var/log/flume
+ networks:
+ sample_network:
+ aliases:
+ - flume
+
+ sampleapp:
+ container_name: sampleapp
+ image: sampleapp
+ environment:
+ DOCKER_URI: http://socat:1234
+ SERVICE_PARAMS:
--spring.config.location=classpath:/,classpath:/application-local-docker.yml
+ ports:
+ - "5005:5005"
+ - "8080:8080"
+ networks:
+ sample_network:
+ aliases:
+ - sampleapp
+networks:
+ sample_network:
+
+volumes:
+ pgdata:
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/docker-compose.yml
b/log4j-spring-cloud-config-sample-application/docker/docker-compose.yml
new file mode 100755
index 0000000..0d76f52
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/docker-compose.yml
@@ -0,0 +1,74 @@
+version: "3"
+services:
+ socat:
+ container_name: socat
+ image: bobrik/socat
+ command: TCP-LISTEN:1234,fork UNIX-CONNECT:/var/run/docker.sock
+ expose:
+ - "1234"
+ volumes:
+ - /var/run/docker.sock:/var/run/docker.sock
+ networks:
+ sample_network:
+ aliases:
+ - socat
+
+ rabbitmq:
+ container_name: rabbit
+ image: rabbitmq:3-management-alpine
+ expose:
+ - "5672"
+ - "15672"
+ ports:
+ - "5672:5672"
+ - "15672:15672"
+ volumes:
+ - ./init/rabbit/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
+ - ./init/rabbit/definitions.json:/etc/rabbitmq/definitions.json:ro
+ networks:
+ sample_network:
+ aliases:
+ - rabbitmq
+
+ fluent-bit:
+ container_name: fluent-bit
+ image: fluent/fluent-bit:latest
+ expose:
+ - "2020"
+ - "24221"
+ - "24224"
+ ports:
+ - "24224:24224"
+ volumes:
+ - ./init/fluent-bit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
+ - ./target/logs:/var/logs
+ networks:
+ sample_network:
+ aliases:
+ - fluent-bit
+
+ flume:
+ container_name: flume
+ image: probablyfine/flume:latest
+ expose:
+ - "5050"
+ environment:
+ FLUME_AGENT_NAME: forwarder
+ FLUME_JAVA_OPTS:
-Dlog4j.configuration=file:///opt/flume-config/log4j.properties
+ volumes:
+ - ./init/flume/start-flume.sh:/opt/flume/bin/start-flume
+ - ./init/flume/flume.conf:/opt/flume-config/flume.conf
+ - ./init/flume/flume-env.sh:/opt/flume-config/flume-env.sh
+ - ./init/flume/log4j.properties:/opt/flume-config/log4j.properties
+ - ~/flume-logs:/var/log/flume
+ networks:
+ sample_network:
+ aliases:
+ - flume
+
+
+networks:
+ sample_network:
+
+volumes:
+ pgdata:
\ No newline at end of file
diff --git a/log4j-spring-cloud-config-sample-application/docker/down.sh
b/log4j-spring-cloud-config-sample-application/docker/down.sh
new file mode 100755
index 0000000..347c514
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/down.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+echo Stopping containers and removing containers, networks, volumes, and
images created by up.
+DIR=`dirname "$0"`
+docker-compose --file ${DIR}/docker-compose.yml down --rmi local -v
+docker-compose --file ${DIR}/docker-compose.yml rm --force -v
diff --git
a/log4j-spring-cloud-config-sample-application/docker/init/fluent-bit/fluent-bit.conf
b/log4j-spring-cloud-config-sample-application/docker/init/fluent-bit/fluent-bit.conf
new file mode 100644
index 0000000..170c7bd
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/docker/init/fluent-bit/fluent-bit.conf
@@ -0,0 +1,28 @@
+[SERVICE]
+ Log_Level debug
+
+ HTTP_Server On
+ HTTP_Listen 0.0.0.0
+ HTTP_Port 2020
+ Parsers_File parsers.conf
+
+[INPUT]
+ Name tcp
+ Listen 0.0.0.0
+ Port 24221
+ Chunk_Size 32
+ Buffer_Size 64
+
+[INPUT]
+ Name tail
+ Tag kube.*
+ Path /var/log/containers/*.log
+ Parser docker
+ DB /var/log/flb_kube.db
+ Mem_Buf_Limit 5MB
+ Skip_Long_Lines On
+ Refresh_Interval 10
+
+[OUTPUT]
+ Name stdout
+ Match *
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/init/flume/flume-env.sh
b/log4j-spring-cloud-config-sample-application/docker/init/flume/flume-env.sh
new file mode 100644
index 0000000..5137868
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/docker/init/flume/flume-env.sh
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+JAVA_OPTS="-Xmx200m"
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/init/flume/flume.conf
b/log4j-spring-cloud-config-sample-application/docker/init/flume/flume.conf
new file mode 100644
index 0000000..2d928c0
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/init/flume/flume.conf
@@ -0,0 +1,48 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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
+#
+# http://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.
+#
+# Accepts incoming requests and forwards them
+
+# Name the components on this agent
+forwarder.sources = avro
+forwarder.sinks = sink1
+forwarder.channels = channel1
+
+# Describe/configure the source
+forwarder.sources.avro.type = avro
+forwarder.sources.avro.bind = 0.0.0.0
+forwarder.sources.avro.port = 5050
+forwarder.sources.avro.compression-type = none
+
+
+# Describe the sink
+forwarder.sinks.sink1.type = logger
+
+forwarder.sinks.sink1.type = file_roll
+forwarder.sinks.sink1.sink.directory = /var/log/flume/
+forwarder.sinks.sink1.sink.pathManager.extension=log
+forwarder.sinks.sink1.channel = channel1
+forwarder.sinks.sink1.sink.rollInterval = 300
+forwarder.sinks.sink1.sink.serializer = text
+
+# Use a channel which buffers events in memory
+forwarder.channels.channel1.type = memory
+forwarder.channels.channel1.capacity = 100000
+forwarder.channels.channel1.transactionCapacity = 10000
+
+# Bind the source and sink to the channel
+forwarder.sources.avro.channels = channel1
+forwarder.sinks.sink1.channel = channel1
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/init/flume/log4j.properties
b/log4j-spring-cloud-config-sample-application/docker/init/flume/log4j.properties
new file mode 100644
index 0000000..de51e18
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/docker/init/flume/log4j.properties
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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
+#
+# http://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.
+#
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=INFO, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/init/flume/start-flume.sh
b/log4j-spring-cloud-config-sample-application/docker/init/flume/start-flume.sh
new file mode 100755
index 0000000..6b2a26c
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/docker/init/flume/start-flume.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+
+FLUME_CONF_DIR=/opt/flume-config
+
+[[ -d "${FLUME_CONF_DIR}" ]] || { echo "Flume config file not mounted in
/opt/flume-config"; exit 1; }
+[[ -z "${FLUME_AGENT_NAME}" ]] && { echo "FLUME_AGENT_NAME required"; exit 1; }
+
+echo "Starting flume agent : ${FLUME_AGENT_NAME}"
+
+flume-ng agent \
+ -c ${FLUME_CONF_DIR} \
+ -f ${FLUME_CONF_DIR}/flume.conf \
+ -n ${FLUME_AGENT_NAME} \
+ $*
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/init/rabbit/definitions.json
b/log4j-spring-cloud-config-sample-application/docker/init/rabbit/definitions.json
new file mode 100644
index 0000000..835f10e
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/docker/init/rabbit/definitions.json
@@ -0,0 +1,36 @@
+{
+ "rabbit_version": "3.6.14",
+ "users": [
+ {
+ "name": "guest",
+ "password_hash": "8NWJazmxFqF0nohjVsE6rRP9wvwzEq/fpUel2in5Y3YAE3KZ",
+ "hashing_algorithm": "rabbit_password_hashing_sha256",
+ "tags": "administrator"
+ }
+ ],
+ "vhosts": [
+ {
+ "name": "/"
+ }
+ ],
+ "permissions": [
+ {
+ "user": "guest",
+ "vhost": "/",
+ "configure": ".*",
+ "write": ".*",
+ "read": ".*"
+ }
+ ],
+ "parameters": [],
+ "global_parameters": [
+ {
+ "name": "cluster_name",
+ "value": "rabbit@c85301775966"
+ }
+ ],
+ "policies": [],
+ "queues": [],
+ "exchanges": [],
+ "bindings": []
+}
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/docker/init/rabbit/rabbitmq.config
b/log4j-spring-cloud-config-sample-application/docker/init/rabbit/rabbitmq.config
new file mode 100644
index 0000000..b55f508
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/docker/init/rabbit/rabbitmq.config
@@ -0,0 +1,14 @@
+[
+ {
+ rabbit,
+ [
+ { loopback_users, [] }
+ ]
+ },
+ {
+ rabbitmq_management,
+ [
+ { load_definitions, "/etc/rabbitmq/definitions.json" }
+ ]
+ }
+].
\ No newline at end of file
diff --git a/log4j-spring-cloud-config-sample-application/docker/logs.sh
b/log4j-spring-cloud-config-sample-application/docker/logs.sh
new file mode 100755
index 0000000..675ed6a
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/logs.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+
+DIR=`dirname "$0"`
+# dump existing logs and start tailing them
+# https://docs.docker.com/compose/reference/logs
+docker-compose --file ${DIR}/../docker/docker-compose.yml logs --follow
--tail=all
+
diff --git a/log4j-spring-cloud-config-sample-application/docker/restartApp.sh
b/log4j-spring-cloud-config-sample-application/docker/restartApp.sh
new file mode 100755
index 0000000..6bb6fac
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/restartApp.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+imageName=sampleapp
+containerName=app-container
+networkName=docker_sample_network
+debug_port=5005
+#debug_expose="-p $debug_port:$debug_port"
+exposed_ports="-p 8080:8080 $debug_expose"
+
+mvn clean package -DskipTests=true
+
+docker build -t $imageName -f Dockerfile .
+
+echo Delete old container...
+docker rm -f $containerName
+
+echo Run new container...
+docker run -e
"SERVICE_PARAMS=--spring.config.location=classpath:/,classpath:/application-local-docker.yml"
\
+ -e "DOCKER_URI=http://socat:1234" \
+ --network=$networkName -d $exposed_ports --name $containerName -h sample
$imageName
+# --log-driver=fluentd --log-opt fluentd-address=host.docker.internal:24224
\
\ No newline at end of file
diff --git a/log4j-spring-cloud-config-sample-application/docker/stop.sh
b/log4j-spring-cloud-config-sample-application/docker/stop.sh
new file mode 100755
index 0000000..e77e6da
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/stop.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+
+echo Stopping running containers without removing them.
+
+DIR=`dirname "$0"`
+docker-compose --file ${DIR}/../docker/docker-compose.yml stop
\ No newline at end of file
diff --git a/log4j-spring-cloud-config-sample-application/docker/stopApp.sh
b/log4j-spring-cloud-config-sample-application/docker/stopApp.sh
new file mode 100755
index 0000000..dae25d8
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/stopApp.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+containerName=app-container
+docker rm -f $containerName
\ No newline at end of file
diff --git a/log4j-spring-cloud-config-sample-application/docker/up.sh
b/log4j-spring-cloud-config-sample-application/docker/up.sh
new file mode 100755
index 0000000..b81df4c
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/docker/up.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+
+echo "Building, (re)creating, starting, and attaching to containers for a
service."
+
+DIR=`dirname "$0"`
+docker-compose --file ${DIR}/docker-compose.yml up --detach --build
\ No newline at end of file
diff --git a/log4j-spring-cloud-config-sample-application/k8s/deploy.sh
b/log4j-spring-cloud-config-sample-application/k8s/deploy.sh
new file mode 100755
index 0000000..9f67de2
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/k8s/deploy.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+
+echo "Building, (re)creating, starting, and attaching to containers for a
service."
+
+imageName=sampleapp
+containerName=sampleapp-container
+networkName=docker_sampleapp
+debug_port=5005
+#debug_expose="-p $debug_port:$debug_port"
+exposed_ports="-p 8080:8090 $debug_expose"
+
+mvn clean package -DskipTests=true
+docker build --no-cache -t $imageName -f Dockerfile .
+
+docker tag $imageName localhost:5000/$imageName
+docker push localhost:5000/$imageName
+kubectl apply -f k8s/sampleapp-deployment.yaml
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/k8s/sampleapp-deployment.yaml
b/log4j-spring-cloud-config-sample-application/k8s/sampleapp-deployment.yaml
new file mode 100644
index 0000000..ffd2851
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/k8s/sampleapp-deployment.yaml
@@ -0,0 +1,53 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: sampleapp
+ labels:
+ app: sampleapp
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: sampleapp
+ template:
+ metadata:
+ labels:
+ app: sampleapp
+ spec:
+ containers:
+ - name: sampleapp
+ image: localhost:5000/sampleapp:latest
+ imagePullPolicy: Always
+ ports:
+ - containerPort: 8080
+ - containerPort: 5005
+ env:
+ - name: JAVA_OPTS
+ value: "-Delastic.search.host=host.docker.internal"
+ - name: key-value-store
+ image: redis
+ ports:
+ - containerPort: 6379
+
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: sampleapp
+spec:
+ selector:
+ app: sampleapp
+ ports:
+ - protocol: TCP
+ port: 8080
+ targetPort: 8080
+ name: http
+ - protocol: TCP
+ port: 6379
+ targetPort: 6379
+ name: redis
+ - protocol: TCP
+ port: 5005
+ targetPort: 5005
+ name: debug
diff --git a/log4j-spring-cloud-config-sample-application/k8s/undeploy.sh
b/log4j-spring-cloud-config-sample-application/k8s/undeploy.sh
new file mode 100755
index 0000000..c5255c9
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/k8s/undeploy.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+#
+
+echo "Building, (re)creating, starting, and attaching to containers for a
service."
+
+imageName=sampleapp
+containerName=sampleapp-container
+networkName=docker_sampleapp
+
+kubectl delete deploy/$imageName svc/$imageName
+
diff --git a/log4j-spring-cloud-config-sample-application/pom.xml
b/log4j-spring-cloud-config-sample-application/pom.xml
new file mode 100644
index 0000000..73ffd00
--- /dev/null
+++ b/log4j-spring-cloud-config-sample-application/pom.xml
@@ -0,0 +1,202 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You 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
+ ~
+ ~ http://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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.logging.log4j.samples</groupId>
+ <artifactId>log4j-samples</artifactId>
+ <version>${revision}</version>
+ </parent>
+
+ <artifactId>log4j-spring-cloud-config-sample-application</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Apache Log4j Samples: Spring Cloud Config App</name>
+ <properties>
+ <revision>2.19.1-SNAPSHOT</revision>
+ </properties>
+
+ <dependencies>
+
+ <!-- Required for Async Loggers -->
+ <dependency>
+ <groupId>com.lmax</groupId>
+ <artifactId>disruptor</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- Required for Flume embedded -->
+ <dependency>
+ <groupId>org.apache.flume</groupId>
+ <artifactId>flume-ng-embedded-agent</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.flume</groupId>
+ <artifactId>flume-ng-sdk</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-jsr310</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kafka</groupId>
+ <artifactId>kafka-clients</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-docker</artifactId>
+ </dependency>
+
+ <!-- Required for Flume -->
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-flume-ng</artifactId>
+ </dependency>
+ <dependency>
+
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jcl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-kubernetes</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-spring-cloud-config-client</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-log4j2</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ </dependency>
+
+ <!-- Spring Boot dependencies -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <!-- Spring Cloud dependencies -->
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-bus-amqp</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Spring Tests -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/Test*.java</include>
+ <include>**/*Test.java</include>
+ <include>**/IT*.java</include>
+ <include>**/*IT.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/*FuncTest.java</exclude>
+ </excludes>
+ <forkCount>1</forkCount>
+ <systemPropertyVariables>
+ <environment>${environment}</environment>
+ <site>${site}</site>
+ </systemPropertyVariables>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/SampleApplication.java
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/SampleApplication.java
new file mode 100644
index 0000000..5431e41
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/SampleApplication.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.
+ */
+package org.apache.logging.log4j.spring.cloud.config.sample;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import
org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+
+@SpringBootApplication
+public class SampleApplication extends SpringBootServletInitializer {
+ public static void main(String[] args) {
+ SpringApplication.run(SampleApplication.class, args);
+ }
+
+}
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/config/GlobalExceptionHandler.java
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/config/GlobalExceptionHandler.java
new file mode 100644
index 0000000..2d0317c
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/config/GlobalExceptionHandler.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.
+ */
+package org.apache.logging.log4j.spring.cloud.config.sample.config;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+
+
+@ControllerAdvice
+public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
+
+ private static final Logger LOGGER =
LogManager.getLogger(GlobalExceptionHandler.class);
+
+
+ private ResponseEntity<Object> getResponseEntity(Object responseMessage,
HttpStatus httpStatus) {
+ return new ResponseEntity<>(responseMessage, httpStatus);
+ }
+}
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/config/WebMvcConfig.java
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/config/WebMvcConfig.java
new file mode 100644
index 0000000..24b51cf
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/config/WebMvcConfig.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.
+ */
+package org.apache.logging.log4j.spring.cloud.config.sample.config;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import
org.apache.logging.log4j.spring.cloud.config.sample.utils.spring.SampleResponseErrorHandler;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class WebMvcConfig implements WebMvcConfigurer {
+ private Logger LOGGER = LogManager.getLogger(WebMvcConfig.class);
+
+ @Bean
+ public RestTemplate restTemplate() {
+ RestTemplate restTemplate = new RestTemplate();
+ restTemplate.setErrorHandler(new SampleResponseErrorHandler());
+ return restTemplate;
+ }
+
+
+}
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/controller/K8SController.java
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/controller/K8SController.java
new file mode 100644
index 0000000..145a72d
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/controller/K8SController.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.
+ */
+package org.apache.logging.log4j.spring.cloud.config.sample.controller;
+
+import java.nio.file.Paths;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.kubernetes.KubernetesClientBuilder;
+import org.apache.logging.log4j.util.Strings;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Test class
+ */
+@RestController
+public class K8SController {
+
+ private static final Logger LOGGER =
LogManager.getLogger(K8SController.class);
+ private static final String HOSTNAME = "HOSTNAME";
+ @Autowired
+ private ObjectMapper objectMapper;
+
+ @GetMapping("/k8s/pod")
+ public ResponseEntity<Pod> getPod() {
+ try {
+ KubernetesClient client = new
KubernetesClientBuilder().createClient();
+ if (client != null) {
+ Pod pod = getCurrentPod(client);
+ if (pod != null) {
+ LOGGER.info("Pod: {}",
objectMapper.writeValueAsString(pod));
+ return new ResponseEntity<>(pod, HttpStatus.OK);
+ }
+ }
+ } catch (Exception ex) {
+ LOGGER.error("Unable to obtain or print Pod information", ex);
+ }
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+
+ private Pod getCurrentPod(KubernetesClient kubernetesClient) {
+ String hostName = System.getenv(HOSTNAME);
+ try {
+ if (isServiceAccount() && Strings.isNotBlank(hostName)) {
+ return kubernetesClient.pods().withName(hostName).get();
+ }
+ } catch (Throwable t) {
+ LOGGER.debug("Unable to locate pod with name {}.", hostName);
+ }
+ return null;
+ }
+
+ private boolean isServiceAccount() {
+ return
Paths.get(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH).toFile().exists()
+ &&
Paths.get(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH).toFile().exists();
+ }
+
+}
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/controller/SampleController.java
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/controller/SampleController.java
new file mode 100644
index 0000000..d8bbe58
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/controller/SampleController.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.
+ */
+package org.apache.logging.log4j.spring.cloud.config.sample.controller;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.util.Timer;
+
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+
+
+@RestController
+public class SampleController {
+
+ private static final Logger LOGGER =
LogManager.getLogger(SampleController.class);
+ private static int MAX_MESSAGES = 100000;
+
+ @GetMapping("/log")
+ public ResponseEntity<String> get(@RequestParam(name="threads",
defaultValue="1") int threads,
+ @RequestParam(name="messages", defaultValue="100000") int count) {
+ if (threads < 1) {
+ threads = 1;
+ }
+ if (count < threads) {
+ count = threads * 10000;
+ }
+ if ((count * threads) > MAX_MESSAGES) {
+ count = MAX_MESSAGES / threads;
+ }
+ String msg = "";
+ if (threads == 1) {
+ Timer timer = new Timer("sample");
+ timer.start();
+ for (int n = 0; n < count; ++n) {
+ LOGGER.info("Log record " + n);
+ }
+ timer.stop();
+ StringBuilder sb = new StringBuilder("Elapsed time = ");
+ timer.formatTo(sb);
+ msg = sb.toString();
+ } else {
+ ExecutorService service = Executors.newFixedThreadPool(threads);
+ Timer timer = new Timer("sample");
+ timer.start();
+ for (int i = 0; i < threads; ++i) {
+ service.submit(new Worker(i, count));
+ }
+ service.shutdown();
+ try {
+ service.awaitTermination(2, TimeUnit.MINUTES);
+ timer.stop();
+ StringBuilder sb = new StringBuilder("Elapsed time = ");
+ timer.formatTo(sb);
+ msg = sb.toString();
+ } catch (InterruptedException ex) {
+ msg = "Max time exceeded";
+ }
+ }
+
+ return ResponseEntity.ok(msg);
+ }
+
+ @GetMapping("/exception")
+ public ResponseEntity<String> exception() {
+ Throwable t = new Throwable("This is a test");
+ LOGGER.info("This is a test", t);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(os);
+ t.printStackTrace(ps);
+ String stackTrace = os.toString();
+ stackTrace = stackTrace.replaceAll("\n", "<br>");
+
+ //LOGGER.info("Hello, World");
+ return ResponseEntity.ok(stackTrace);
+ }
+
+ private static class Worker implements Runnable {
+
+ private final int id;
+ private final int count;
+
+ public Worker(int id, int count) {
+ this.id = id;
+ this.count = count;
+ }
+
+ @Override
+ public void run() {
+ String prefix = "Thread " + id + " record ";
+ for (int i = 0; i < count; ++i) {
+ LOGGER.info(prefix + i);
+ }
+ }
+ }
+}
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/utils/spring/SampleResponseErrorHandler.java
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/utils/spring/SampleResponseErrorHandler.java
new file mode 100644
index 0000000..b3e9dc2
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/java/org/apache/logging/log4j/spring/cloud/config/sample/utils/spring/SampleResponseErrorHandler.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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.
+ */
+package org.apache.logging.log4j.spring.cloud.config.sample.utils.spring;
+
+import java.io.IOException;
+
+import org.springframework.http.client.ClientHttpResponse;
+
+/**
+ * Custom http client error handler which doesn't throw exception in case http
code is not 2xx.
+ */
+public class SampleResponseErrorHandler implements
org.springframework.web.client.ResponseErrorHandler {
+ @Override
+ public boolean hasError(ClientHttpResponse clientHttpResponse) throws
IOException {
+ return false;
+ }
+
+ @Override
+ public void handleError(ClientHttpResponse clientHttpResponse) throws
IOException {
+
+ }
+}
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/resources/META-INF/MANIFEST.MF
b/log4j-spring-cloud-config-sample-application/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/resources/application.yml
b/log4j-spring-cloud-config-sample-application/src/main/resources/application.yml
new file mode 100644
index 0000000..4c6bb12
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/resources/application.yml
@@ -0,0 +1,33 @@
+server:
+ port: 8080
+ servlet:
+ context-path: /sample
+
+security:
+ basic:
+ enabled: false
+
+management:
+ security:
+ enabled: false
+
+spring:
+ application:
+ name: sampleapp
+
+ cloud:
+ bus:
+ trace:
+ enabled: true
+ config:
+ watch:
+ enabled: true
+
+ rabbitmq:
+ addresses: rabbit
+ port: 5672
+ username: guest
+ password: guest
+
+log4j2:
+ debug: true
\ No newline at end of file
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/resources/bootstrap.yml
b/log4j-spring-cloud-config-sample-application/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..102e941
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/resources/bootstrap.yml
@@ -0,0 +1,5 @@
+#Spring Cloud (Hystrix) config goes here.
+hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 30000
+logging:
+ config:
http://host.docker.internal:8888/ConfigService/samppleapp/default/master/log4j2.xml
+
diff --git
a/log4j-spring-cloud-config-sample-application/src/main/resources/log4j2.component.properties
b/log4j-spring-cloud-config-sample-application/src/main/resources/log4j2.component.properties
new file mode 100644
index 0000000..54f7d70
--- /dev/null
+++
b/log4j-spring-cloud-config-sample-application/src/main/resources/log4j2.component.properties
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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
+#
+# http://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.
+#
+log4j.configurationFile=http://host.docker.internal:8888/ConfigService/sampleapp/default/master/log4j2.xml
+log4j2.configurationUserName=guest
+log4j2.configurationPassword=guest
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5a09d25..463951b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,24 +41,28 @@
<module>log4j-samples-flume-embedded</module>
<module>log4j-samples-flume-remote</module>
<module>log4j-samples-loggerProperties</module>
+ <module>log4j-spring-cloud-config-sample-application</module>
<module>log4j-spring-cloud-config-sample-server</module>
</modules>
<properties>
<assertj.version>3.24.2</assertj.version>
+ <disruptor.version>3.4.4</disruptor.version>
<flatten-maven-plugin.version>1.3.0</flatten-maven-plugin.version>
<flume.version>1.11.0</flume.version>
<guava.version>27.0.1-jre</guava.version>
+ <jackson.version>2.14.2</jackson.version>
<jetty.version>10.0.13</jetty.version>
<junit.version>5.9.0</junit.version>
<kotlin.version>1.8.10</kotlin.version>
+ <kubernetes-client.version>5.12.4</kubernetes-client.version>
<maven.compiler.release>8</maven.compiler.release>
<!-- Using JDK 8 is incompatible with an increasing number of plugins -->
<minimalJavaBuildVersion>11</minimalJavaBuildVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- project version -->
<revision>2.19.1-SNAPSHOT</revision>
- <snakeyaml.version>1.31</snakeyaml.version>
+ <snakeyaml.version>1.33</snakeyaml.version>
<spotless-maven-plugin.version>2.33.0</spotless-maven-plugin.version>
<spring-boot.version>2.7.8</spring-boot.version>
<spring-cloud.version>2021.0.5</spring-cloud.version>
@@ -78,6 +82,14 @@
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson</groupId>
+ <artifactId>jackson-bom</artifactId>
+ <version>${jackson.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
<!-- Transitive dependency of multiple dependencies -->
<!-- We fix a common version -->
<dependency>
@@ -88,6 +100,14 @@
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>io.fabric8</groupId>
+ <artifactId>kubernetes-client-bom</artifactId>
+ <version>${kubernetes-client.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
@@ -112,6 +132,12 @@
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>com.lmax</groupId>
+ <artifactId>disruptor</artifactId>
+ <version>${disruptor.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.apache.flume.flume-ng-channels</groupId>
<artifactId>flume-file-channel</artifactId>