== Camel Example Spring Boot JTA

This example demonstrates how to run a Camel Service on Spring Boot that supports JTA transactions on two external transactional resources: a database (MySQL) and a message broker (Artemis).

We use Narayana as standalone JTA Transaction Manager implementation, and Hibernate as JPA Adapter.
Most of the configuration is in `src/main/resources/spring-camel.xml` with no auto-configuration magic, in order to show all components needed to support distributed transactions without a full blown application server.

=== External systems

Start MySQL:

----
WORK_DIR="$HOME/.local/mysql"
docker run --name db-mysql \
  -e MYSQL_ROOT_PASSWORD=root \
  -v $WORK_DIR:/var/lib/mysql \
  -d -p 3306:3306 mysql

docker exec -it db-mysql mysql -uroot -proot -e \
  "CREATE DATABASE testdb CHARACTER SET utf8mb4;
   CREATE USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'admin';
   GRANT CREATE,SELECT,INSERT,UPDATE,DELETE ON testdb.* TO 'admin'@'%';
   GRANT XA_RECOVER_ADMIN on *.* to 'admin'@'%';
   FLUSH PRIVILEGES;"
docker exec -it db-mysql mysql testdb -uadmin -padmin -e \
  "CREATE TABLE IF NOT EXISTS audit_log (
    id SERIAL PRIMARY KEY,
    message VARCHAR(255) NOT NULL
  );"
----

Start Artemis:

----
docker run --name artemis \
  -e AMQ_USER=admin \
  -e AMQ_PASSWORD=admin \
  -d -p 61616:61616 \
  quay.io/artemiscloud/activemq-artemis-broker
----

=== How to run

You can run this example using (every instance must have a unique identifier):

----
export NODE_IDENTIFIER="myid0"
mvn clean spring-boot:run
----

Test the service endpoint from another terminal:

----
ADDRESS="http://localhost:8080/api"
curl -X POST $ADDRESS/messages/hello
curl $ADDRESS/messages
----

Test rollback by calling the service with "fail" content:

----
curl -X POST $ADDRESS/messages/fail
----

You should not find any trace of the message in the `audit_log` table.

=== To get health check

To show a summary of spring boot health check:

----
curl http://localhost:8080/actuator/health
----

See the `application.properties` to control what information to present in actuator.

=== Help and contributions

If you hit any problem using Camel or have some feedback, then please https://camel.apache.org/support.html[let us know].

We also love contributors, so https://camel.apache.org/contributing.html[get involved] :-)

The Camel riders!
