Skip to content

Latest commit

 

History

History
292 lines (224 loc) · 7.07 KB

README.adoc

File metadata and controls

292 lines (224 loc) · 7.07 KB

ESB cloud stack

Github CI

The purpose of this repository is to show how to build a custom ESB based on Apache Karaf & Apache Camel to be cloud friendly.

Build

Prerequisite:

  • Maven 3.x

  • JDK 11+

To build the project:

mvn clean install

The platform is available as a tar.gz and zip format in:

├── distribution
│   └── target
│       ├── esbcloud-distribution-1.0.0-SNAPSHOT.jar
│       ├── esbcloud-distribution-1.0.0-SNAPSHOT.tar.gz
│       ├── esbcloud-distribution-1.0.0-SNAPSHOT.zip

The main platform directory is:

├── distribution
│   └── target
│       ├── assembly
│       │   └── karaf

Run

To run the platform in system out mode (for Docker):

./distribution/target/assembly/karaf/bin/karaf run

To run the platform in shell console:

./distribution/target/assembly/karaf/bin/karaf

To run the platform in background process:

./distribution/target/assembly/karaf/bin/start

Configuration

The following properties can be set with system environment variables:

# Logging
LOG4J2_LOGGING_APPENDER_CONSOLE=Console
LOG4J2_LOGGING_PATTERN_CONSOLE={\"@timestamp\": \"%d{yyyy-MM-dd'T'HH:mm:ss.SSS}\", \"level\": \"%p\", \"logger\": \"%logger{63}:%L\", \"thread\": \"%t\", \"classname\": \"%class{63}\", \"message\": \"%encode{%m%wEx{full}}{JSON}\"}%n

# Kafka cluster notification
ESBCLOUD_KAFKA_BROKERS=localhost:9093
ESBCLOUD_KAFKA_TOPIC=dev.si.docawesome
ESBCLOUD_KAFKA_SECURITY_PROTOCOL=SASL_PLAINTEXT
ESBCLOUD_KAFKA_SECURITY_SASL_MECHANISM=SCRAM-SHA-512
ESBCLOUD_KAFKA_SECURITY_SASL_MODULE=org.apache.kafka.common.security.scram.ScramLoginModule
ESBCLOUD_KAFKA_SECURITY_SASL_USERNAME=esbcloud
ESBCLOUD_KAFKA_SECURITY_SASL_PASSWORD=changeit

# Expose api
ESBCLOUD_ENDPOINT_PROTOCOL=http
ESBCLOUD_ENDPOINT_HOST=localhost
ESBCLOUD_ENDPOINT_PORT=8080
ESBCLOUD_ENDPOINT_CXF_TRACE_ACTIVE=false

# API Gateway credentials for external poll
ESBCLOUD_POLL_CLIENT_USERNAME=esbcloud
ESBCLOUD_POLL_CLIENT_PASSWORD=changeit

When running the instance locally you can define the properties in

./distribution/target/assembly/karaf/bin/karaf/etc/io.yupiik.esb.routes.camelcontext.cfg
./distribution/target/assembly/karaf/bin/karaf/etc/io.yupiik.esb.services.endpoint.camelcontext.cfg
./distribution/target/assembly/karaf/bin/karaf/etc/io.yupiik.esb.services.observability.camelcontext.cfg

Properties are loaded by Felix ConfigAdmin interpolate:

# API published entrypoint
esbcloud.endpoint.host=$[env:ESBCLOUD_ENDPOINT_HOST=localhost]
esbcloud.endpoint.port=$[env:ESBCLOUD_ENDPOINT_PORT=8080]
esbcloud.endpoint.protocol=$[env:ESBCLOUD_ENDPOINT_PROTOCOL=http]
esbcloud.endpoint.cxf.trace.active==$[env:ESBCLOUD_ENDPOINT_CXF_TRACE_ACTIVE;default=false]

You can replace the default values.

Development

Debug

To debug code you have to run the distribution in debug mode:

./distribution/target/assembly/karaf/bin/karaf debug

Remote debug is now available on localhost:5005

Then you can activate the bundle refresh watching:

karaf@root()> bundle:watch *

When building a maven module, it will be automatically reloaded in the running instance. You don’t need to build all the project.

Tail log:

karaf@root()> log:tail

Test

Send notification to jms

curl -X 'POST' \
  'http://localhost:8080/notification' \
  -H 'accept: application/json;charset=utf-8' \
  -H 'X-Routing-System: jms' \
  -H 'Content-Type: application/json;charset=utf-8' \
  -d '{
  "reference": "INF161200001",
  "date": "01/01/1970 00:00:00",
  "message": "Update contract"
}'

Send notification to kafka

curl -X 'POST' \
  'http://localhost:8080/notification' \
  -H 'accept: application/json;charset=utf-8' \
  -H 'X-Routing-System: kafka' \
  -H 'Content-Type: application/json;charset=utf-8' \
  -d '{
  "reference": "INF161200001",
  "date": "01/01/1970 00:00:00",
  "message": "Update contract"
}'

Send notification to unknown system (will fail)

curl -X 'POST' \
  'https://localhost:8080/notification' \
  -H 'accept: application/json;charset=utf-8' \
  -H 'X-Routing-System: unknown' \
  -H 'Content-Type: application/json;charset=utf-8' \
  -d '{
  "reference": "INF161200001",
  "date": "01/01/1970 00:00:00",
  "message": "Update contract"
}'

E2E with Cucumber

The cucumber e2e tests are located in the esbcloud-distribution module.

To launch them, just run the command:

mvn test -Pe2e-on-dev

Load test with JMeter

The JMeter load tests are located in the esbcloud-distribution module.

To launch them, just run the command:

mvn jmeter:configure jmeter:jmeter jmeter:results -Pperformance

You can update the load test in src/test/jmeter/jmeter-test-plan.jmx

Docker

The configuration of the docker build is done with the maven-jib-plugin

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>3.3.1</version>
    <configuration>
        <allowInsecureRegistries>true</allowInsecureRegistries>
        <from>
            <image>ossyupiik/java:17.0.4</image> (1)
        </from>
        <to>
            <image>io.yupiik.esbcloud/esbcloud-distribution:${project.version}</image> (2)
        </to>
        <container>
            <entrypoint> (3)
                <entrypoint>/karaf/bin/karaf</entrypoint>
                <entrypoint>run</entrypoint>
            </entrypoint>
            <workingDirectory>/karaf</workingDirectory>
        </container>
        <extraDirectories>
            <paths>
                <path>target/assembly</path>
            </paths>
            <permissions>
                <permission>
                    <file>/karaf/bin/karaf</file>
                    <mode>755</mode>
                </permission>
            </permissions>
        </extraDirectories>
    </configuration>
</plugin>
  1. The docker image base

  2. The docker image to build

  3. The entrypoint of the command to execute when running the docker

Health checks are available at:

mvn compile jib:dockerBuild

You can see the image on your local docker registry:

docker images
>
REPOSITORY                                                  TAG                   IMAGE ID            CREATED             SIZE
io.yupiik.esbcloud/esbcloud-distribution                    1.0.0-SNAPSHOT        29df4227923c        1 years ago        490MB

Now you can run a container:

docker run -it --name esbcloud io.yupiik.esbcloud/esbcloud-distribution:1.0.0-SNAPSHOT