This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git

commit 6da7fd3de765095627ff424f601681abf1f4c64f
Author: Zheng Feng <zh.f...@gmail.com>
AuthorDate: Sun Jun 26 22:33:51 2022 +0800

    Add jta-jpa example
---
 docs/modules/ROOT/attachments/examples.json       |   5 +
 jta-jpa/README.adoc                               | 166 +++++++++++
 jta-jpa/pom.xml                                   | 317 ++++++++++++++++++++++
 jta-jpa/src/main/java/org/acme/AuditLog.java      |  61 +++++
 jta-jpa/src/main/java/org/acme/CamelRoutes.java   |  62 +++++
 jta-jpa/src/main/resources/application.properties |  49 ++++
 jta-jpa/src/test/java/org/acme/JtaIT.java         |  23 ++
 jta-jpa/src/test/java/org/acme/JtaTest.java       |  62 +++++
 jta-jpa/src/test/resources/broker.xml             |  44 +++
 9 files changed, 789 insertions(+)

diff --git a/docs/modules/ROOT/attachments/examples.json 
b/docs/modules/ROOT/attachments/examples.json
index bfe2be9..58fde5c 100644
--- a/docs/modules/ROOT/attachments/examples.json
+++ b/docs/modules/ROOT/attachments/examples.json
@@ -29,6 +29,11 @@
     "description": "Shows how to use Camel health-checks with Quarkus.",
     "link": "https://github.com/apache/camel-quarkus-examples/tree/main/health";
   },
+  {
+    "title": "JTA and JPA",
+    "description": "Shows how to run a Camel Quarkus application that supports 
JTA transactions on two external transactional resources: a database (MySQL) 
and a message broker (Artemis).",
+    "link": 
"https://github.com/apache/camel-quarkus-examples/tree/main/jta-jpa";
+  },
   {
     "title": "Kafka example ",
     "description": "Shows how to produce and consume messages in a Kafka 
topic, using Strimzi Operator",
diff --git a/jta-jpa/README.adoc b/jta-jpa/README.adoc
new file mode 100644
index 0000000..037ff4a
--- /dev/null
+++ b/jta-jpa/README.adoc
@@ -0,0 +1,166 @@
+= JTA and JPA: A Camel Quarkus example
+:cq-example-description: An example that shows how to run a Camel Quarkus 
application that supports JTA transactions on two external transactional 
resources: a database (MySQL) and a message broker (Artemis).
+
+{cq-description}
+
+We use Narayana as standalone JTA Transaction Manager implementation, and 
Hibernate as JPA Adapter.
+
+This example will connect to a database with the connection details defined in 
`application.properties`.
+If the example is run on Development mode and no database exists, Quarkus will 
create a matching database
+https://quarkus.io/guides/datasource#dev-services[as described here].
+
+TIP: Check the 
https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus 
User guide] for prerequisites
+and other general information.
+
+NOTE: The Narayana `node.identifier` is very important when you scale up in 
the cloud environment. It must be unique for each node. You can set it by using 
`quarkus.transaction-manager.node-name` property which the default value is `1`.
+
+.Todo crash recovery issues
+- https://github.com/quarkiverse/quarkus-pooled-jms/issues/9[Add XA Recovery 
helper in quarkus-pooled-jms #9]
+- https://github.com/quarkusio/quarkus/issues/26160[Improve recovery manager 
in quarkus-narayana-jta extension #26160]
+
+== Start in the Development mode
+
+[source,shell]
+----
+$ mvn clean compile quarkus:dev
+----
+
+The above command compiles the project, starts the application and lets the 
Quarkus tooling watch for changes in your
+workspace. Any modifications in your project will automatically take effect in 
the running application.
+
+TIP: Please refer to the Development mode section of
+https://camel.apache.org/camel-quarkus/latest/first-steps.html#_development_mode[Camel
 Quarkus User guide] for more details.
+
+== Package and run the application
+
+Once you are done with developing you may want to package and run the 
application.
+
+TIP: Find more details about the JVM mode and Native mode in the Package and 
run section of
+https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_the_application[Camel
 Quarkus User guide]
+
+==== External systems
+
+Start MySQL:
+[source, shell]
+----
+docker run --name db-mysql \
+  -e MYSQL_ROOT_PASSWORD=root \
+  -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 ALL ON testdb.* TO 'admin'@'%';
+   GRANT XA_RECOVER_ADMIN on *.* to 'admin'@'%';
+   FLUSH PRIVILEGES;"
+----
+
+Start Artemis:
+[source, shell]
+----
+docker run --name artemis \
+  -e AMQ_USER=admin -e AMQ_PASSWORD=admin \
+  -d -p 61616:61616 \
+  quay.io/artemiscloud/activemq-artemis-broker
+----
+
+==== Prerequisites
+- Make sure `io.quarkus:quarkus-jdbc-mysql` has been added in `pom.xml`
+- Make sure `db-mysql` and `artemis` has been started and ready for servicing
+- Edit `src/main/resource/application.properties` to uncomment all `%prod` 
lines
+[source, properties]
+----
+# Production Datasource
+%prod.quarkus.datasource.db-kind=mysql
+%prod.quarkus.datasource.username=admin
+$prod.quarkus.datasource.password=admin
+%prod.quarkus.datasource.jdbc.url=mysql://localhost:3306/testdb
+%prod.quarkus.datasource.jdbc.transactions=xa
+
+# Quarkus Artemis and Messaginghub Pooled JMS
+%prod.quarkus.artemis.url=tcp://localhost:61616
+%prod.quarkus.artemis.username=admin
+%prod.quarkus.artemis.password=admin
+quarkus.pooled-jms.xa.enabled=true
+----
+
+==== JVM mode
+
+[source,shell]
+----
+$ mvn clean package
+$ java -jar target/quarkus-app/quarkus-run.jar
+...
+
+[io.quarkus] (main) camel-quarkus-examples-... started in 0.570s.
+----
+
+==== Native mode
+
+IMPORTANT: Native mode requires having GraalVM and other tools installed. 
Please check the Prerequisites section
+of 
https://camel.apache.org/camel-quarkus/latest/first-steps.html#_prerequisites[Camel
 Quarkus User guide].
+
+To prepare a native executable using GraalVM, run the following command:
+
+[source,shell]
+----
+$ mvn clean package -Pnative
+$ ./target/*-runner
+...
+[io.quarkus] (main) camel-quarkus-examples-... started in 0.011s.
+...
+----
+
+==== How to run
+Test the service endpoint from another terminal:
+
+[source,shell]
+----
+ADDRESS="http://localhost:8080";
+curl -X POST $ADDRESS/api/messages/hello
+curl $ADDRESS/api/messages
+----
+
+Test with normal "hello" content:
+[source,shell]
+----
+curl -X POST $ADDRESS/api/message/hello
+----
+
+Check the audit_log
+[source,shell]
+----
+curl $ADDRESS/api/messages
+----
+You should get some results like
+[source]
+----
+[{message=hello}, {message=hello-ok}]
+----
+
+Test rollback by calling the service with "fail" content:
+[source,shell]
+----
+curl -X POST $ADDRESS/api/message/fail
+----
+You should not find any trace of the message in the audit_log table. And some 
failures like
+[source]
+----
+2022-07-01 11:03:10,257 INFO  [route2] (executor-thread-0) Forced exception
+2022-07-01 11:03:10,257 ERROR [org.apa.cam.pro.err.DefaultErrorHandler] 
(executor-thread-0) Failed delivery for (MessageId: 
0BE5920FE20C353-0000000000000001 on ExchangeId: 
0BE5920FE20C353-0000000000000001). Exhausted after delivery attempt: 1 caught: 
java.lang.RuntimeException: fail
+
+Message History (source location and message history is disabled)
+---------------------------------------------------------------------------------------------------------------------------------------
+Source                                   ID                             
Processor                                          Elapsed (ms)
+                                         route5/route5                  
from[platform-http:///api/messages/%7Bmessage%7D?h            4
+       ...
+                                         route2/process1                
Processor@0x60941009                                          0
+
+Stacktrace
+---------------------------------------------------------------------------------------------------------------------------------------:
 java.lang.RuntimeException: fail
+
+----
+
+== Feedback
+
+Please report bugs and propose improvements via 
https://github.com/apache/camel-quarkus/issues[GitHub issues of Camel Quarkus] 
project.
diff --git a/jta-jpa/pom.xml b/jta-jpa/pom.xml
new file mode 100644
index 0000000..3a172b7
--- /dev/null
+++ b/jta-jpa/pom.xml
@@ -0,0 +1,317 @@
+<?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 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd"; 
xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.camel.quarkus.examples</groupId>
+    <artifactId>camel-quarkus-examples-jta-jpa</artifactId>
+    <version>2.11.0-SNAPSHOT</version>
+    <name>Camel Quarkus :: Examples :: JTA JPA</name>
+    <description>Camel Quarkus Example :: JTA JPA</description>
+    <properties>
+        <quarkus.platform.version>2.10.0.Final</quarkus.platform.version>
+        
<camel-quarkus.platform.version>2.11.0-SNAPSHOT</camel-quarkus.platform.version>
+        <quarkus-artemis.version>1.2.0</quarkus-artemis.version>
+        <quarkus-pooled-jms.version>1.0.1</quarkus-pooled-jms.version>
+
+        <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
+        
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
+        
<camel-quarkus.platform.group-id>org.apache.camel.quarkus</camel-quarkus.platform.group-id>
+        
<camel-quarkus.platform.artifact-id>camel-quarkus-bom</camel-quarkus.platform.artifact-id>
+
+        <formatter-maven-plugin.version>2.17.1</formatter-maven-plugin.version>
+        <impsort-maven-plugin.version>1.3.2</impsort-maven-plugin.version>
+        <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
+        <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
+        <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
+        <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
+        <maven.compiler.source>11</maven.compiler.source>
+        <maven.compiler.target>11</maven.compiler.target>
+        
<maven.compiler.testSource>${maven.compiler.source}</maven.compiler.testSource>
+        
<maven.compiler.testTarget>${maven.compiler.target}</maven.compiler.testTarget>
+        <mycila-license.version>3.0</mycila-license.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    </properties>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>${quarkus.platform.group-id}</groupId>
+                <artifactId>${quarkus.platform.artifact-id}</artifactId>
+                <version>${quarkus.platform.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>${camel-quarkus.platform.group-id}</groupId>
+                <artifactId>${camel-quarkus.platform.artifact-id}</artifactId>
+                <version>${camel-quarkus.platform.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>io.quarkiverse.artemis</groupId>
+                <artifactId>quarkus-artemis-bom</artifactId>
+                <version>${quarkus-artemis.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-microprofile-health</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-rest</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-log</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-bean</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-jms</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-jta</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-narayana-jta</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-jdbc-h2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-jdbc-mysql</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkiverse.artemis</groupId>
+            <artifactId>quarkus-artemis-jms</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkiverse.messaginghub</groupId>
+            <artifactId>quarkus-pooled-jms</artifactId>
+            <version>${quarkus-pooled-jms.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-test-h2</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkiverse.artemis</groupId>
+            <artifactId>quarkus-test-artemis</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.rest-assured</groupId>
+            <artifactId>rest-assured</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>net.revelc.code.formatter</groupId>
+                    <artifactId>formatter-maven-plugin</artifactId>
+                    <version>${formatter-maven-plugin.version}</version>
+                    <configuration>
+                        
<configFile>${maven.multiModuleProjectDirectory}/eclipse-formatter-config.xml</configFile>
+                        <lineEnding>LF</lineEnding>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>net.revelc.code</groupId>
+                    <artifactId>impsort-maven-plugin</artifactId>
+                    <version>${impsort-maven-plugin.version}</version>
+                    <configuration>
+                        <groups>java.,javax.,org.w3c.,org.xml.,junit.</groups>
+                        <removeUnused>true</removeUnused>
+                        <staticAfter>true</staticAfter>
+                        
<staticGroups>java.,javax.,org.w3c.,org.xml.,junit.</staticGroups>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-compiler-plugin</artifactId>
+                    <version>${maven-compiler-plugin.version}</version>
+                    <configuration>
+                        <showDeprecation>true</showDeprecation>
+                        <showWarnings>true</showWarnings>
+                        <compilerArgs>
+                            <arg>-Xlint:unchecked</arg>
+                        </compilerArgs>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-surefire-plugin</artifactId>
+                    <version>${maven-surefire-plugin.version}</version>
+                    <configuration>
+                        <failIfNoTests>false</failIfNoTests>
+                        <systemProperties>
+                            
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+                        </systemProperties>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>${quarkus.platform.group-id}</groupId>
+                    <artifactId>quarkus-maven-plugin</artifactId>
+                    <version>${quarkus.platform.version}</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-failsafe-plugin</artifactId>
+                    <version>${maven-surefire-plugin.version}</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-jar-plugin</artifactId>
+                    <version>${maven-jar-plugin.version}</version>
+                </plugin>
+                <plugin>
+                    <groupId>com.mycila</groupId>
+                    <artifactId>license-maven-plugin</artifactId>
+                    <version>${mycila-license.version}</version>
+                    <configuration>
+                        <failIfUnknown>true</failIfUnknown>
+                        
<header>${maven.multiModuleProjectDirectory}/header.txt</header>
+                        <excludes>
+                            <exclude>**/*.adoc</exclude>
+                            <exclude>**/*.csv</exclude>
+                            <exclude>**/*.txt</exclude>
+                            <exclude>**/LICENSE.txt</exclude>
+                            <exclude>**/LICENSE</exclude>
+                            <exclude>**/NOTICE.txt</exclude>
+                            <exclude>**/NOTICE</exclude>
+                            <exclude>**/README</exclude>
+                            <exclude>**/pom.xml.versionsBackup</exclude>
+                        </excludes>
+                        <mapping>
+                            <java>SLASHSTAR_STYLE</java>
+                            <properties>CAMEL_PROPERTIES_STYLE</properties>
+                            <kt>SLASHSTAR_STYLE</kt>
+                            <xml>XML_STYLE</xml>
+                        </mapping>
+                        <headerDefinitions>
+                            
<headerDefinition>${maven.multiModuleProjectDirectory}/license-properties-headerdefinition.xml</headerDefinition>
+                        </headerDefinitions>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+        <plugins>
+            <plugin>
+                <groupId>${quarkus.platform.group-id}</groupId>
+                <artifactId>quarkus-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>build</id>
+                        <goals>
+                            <goal>build</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <workingDir>${project.basedir}</workingDir>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>net.revelc.code.formatter</groupId>
+                <artifactId>formatter-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>format</id>
+                        <phase>process-sources</phase>
+                        <goals>
+                            <goal>format</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>net.revelc.code</groupId>
+                <artifactId>impsort-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>sort-imports</id>
+                        <phase>process-sources</phase>
+                        <goals>
+                            <goal>sort</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    <profiles>
+        <profile>
+            <id>native</id>
+            <activation>
+                <property>
+                    <name>native</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                                <configuration>
+                                    <systemPropertyVariables>
+                                        
<quarkus.package.type>${quarkus.package.type}</quarkus.package.type>
+                                    </systemPropertyVariables>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+            <properties>
+                <quarkus.package.type>native</quarkus.package.type>
+            </properties>
+        </profile>
+    </profiles>
+</project>
diff --git a/jta-jpa/src/main/java/org/acme/AuditLog.java 
b/jta-jpa/src/main/java/org/acme/AuditLog.java
new file mode 100644
index 0000000..c17365b
--- /dev/null
+++ b/jta-jpa/src/main/java/org/acme/AuditLog.java
@@ -0,0 +1,61 @@
+/*
+ * 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.acme;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@Entity
+@Table(name = "audit_log")
+@NamedQueries({
+        @NamedQuery(name = "getAuditLog", query = "select al from AuditLog al")
+})
+@Named("auditLog")
+@ApplicationScoped
+@RegisterForReflection
+public class AuditLog {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+    private String message;
+
+    public String getMessage() {
+        return message;
+    }
+
+    public AuditLog createAuditLog(String message) {
+        AuditLog auditLog = new AuditLog();
+        auditLog.message = message;
+        return auditLog;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("{message=%s}", message);
+    }
+}
diff --git a/jta-jpa/src/main/java/org/acme/CamelRoutes.java 
b/jta-jpa/src/main/java/org/acme/CamelRoutes.java
new file mode 100644
index 0000000..f4544dc
--- /dev/null
+++ b/jta-jpa/src/main/java/org/acme/CamelRoutes.java
@@ -0,0 +1,62 @@
+/*
+ * 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.acme;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.rest.RestParamType;
+
+@ApplicationScoped
+public class CamelRoutes extends RouteBuilder {
+    @Override
+    public void configure() {
+        rest("/messages")
+                .produces("text/plain")
+                .get()
+                .to("direct:messages")
+                .post("/{message}")
+                
.param().name("message").type(RestParamType.path).dataType("string").endParam()
+                .to("direct:trans");
+
+        from("direct:messages")
+                .to("jpa:org.acme.AuditLog?namedQuery=getAuditLog")
+                .convertBodyTo(String.class);
+
+        from("direct:trans")
+                .transacted()
+                .setBody(simple("${headers.message}"))
+                .to("bean:auditLog?method=createAuditLog(${body})")
+                .to("jpa:org.acme.AuditLog")
+                .setBody(simple("${headers.message}"))
+                .to("jms:outbound?disableReplyTo=true")
+                .choice()
+                .when(body().startsWith("fail"))
+                .log("Forced exception")
+                .process(x -> {
+                    throw new RuntimeException("fail");
+                })
+                .otherwise()
+                .log("Message added: ${body}")
+                .endChoice();
+
+        from("jms:outbound")
+                .log("Message out: ${body}")
+                .to("bean:auditLog?method=createAuditLog(${body}-ok)")
+                .to("jpa:org.acme.AuditLog");
+    }
+}
diff --git a/jta-jpa/src/main/resources/application.properties 
b/jta-jpa/src/main/resources/application.properties
new file mode 100644
index 0000000..caa9103
--- /dev/null
+++ b/jta-jpa/src/main/resources/application.properties
@@ -0,0 +1,49 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+#
+# Quarkus
+#
+quarkus.banner.enabled = false
+quarkus.log.file.enable = true
+
+# Default Datasource
+quarkus.datasource.db-kind=h2
+quarkus.datasource.jdbc.max-size=8
+quarkus.datasource.jdbc.transactions=xa
+
+# Production Datasource
+#%prod.quarkus.datasource.db-kind=mysql
+#%prod.quarkus.datasource.username=admin
+#%prod.quarkus.datasource.password=admin
+#%prod.quarkus.datasource.jdbc.url=jdbc:mysql://localhost:3306/testdb
+#%prod.quarkus.datasource.jdbc.transactions=xa
+
+# Hibernate ORM
+quarkus.hibernate-orm.database.generation=drop-and-create
+
+# Quarkus Artemis and Messaginghub Pooled JMS
+%test.quarkus.artemis.devservices.enabled=false
+#%prod.quarkus.artemis.url=tcp://localhost:61616
+#%prod.quarkus.artemis.username=admin
+#%prod.quarkus.artemis.password=admin
+quarkus.pooled-jms.xa.enabled=true
+
+# Quarkus Narayana JTA
+quarkus.transaction-manager.object-store-directory=target/narayana
+
+# Camel
+camel.rest.context-path=/api
diff --git a/jta-jpa/src/test/java/org/acme/JtaIT.java 
b/jta-jpa/src/test/java/org/acme/JtaIT.java
new file mode 100644
index 0000000..a3d7f98
--- /dev/null
+++ b/jta-jpa/src/test/java/org/acme/JtaIT.java
@@ -0,0 +1,23 @@
+/*
+ * 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.acme;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+public class JtaIT extends JtaTest {
+}
diff --git a/jta-jpa/src/test/java/org/acme/JtaTest.java 
b/jta-jpa/src/test/java/org/acme/JtaTest.java
new file mode 100644
index 0000000..9375ea9
--- /dev/null
+++ b/jta-jpa/src/test/java/org/acme/JtaTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.acme;
+
+import java.util.UUID;
+
+import io.quarkus.artemis.test.ArtemisTestResource;
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.h2.H2DatabaseTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.is;
+
+@QuarkusTest
+@QuarkusTestResource(H2DatabaseTestResource.class)
+@QuarkusTestResource(ArtemisTestResource.class)
+public class JtaTest {
+    @Test
+    public void testXA() {
+        String body = UUID.randomUUID().toString();
+
+        given().when().post("/api/messages/" + body)
+                .then()
+                .statusCode(200);
+
+        given()
+                .when().get("/api/messages")
+                .then()
+                .statusCode(200)
+                .body(is("[{message=" + body + "}, {message=" + body + 
"-ok}]"));
+    }
+
+    @Test
+    public void testRollback() {
+        String result = given().when().get("/api/messages").asString();
+
+        given().when().post("/api/messages/fail")
+                .then()
+                .statusCode(500);
+
+        given().when().get("/api/messages")
+                .then()
+                .statusCode(200)
+                .body(is(result));
+    }
+}
diff --git a/jta-jpa/src/test/resources/broker.xml 
b/jta-jpa/src/test/resources/broker.xml
new file mode 100644
index 0000000..3f6e095
--- /dev/null
+++ b/jta-jpa/src/test/resources/broker.xml
@@ -0,0 +1,44 @@
+<!--
+
+    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.
+
+-->
+<configuration xmlns="urn:activemq" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
+    <core xmlns="urn:activemq:core">
+        <paging-directory>./target/artemis/paging</paging-directory>
+        <bindings-directory>./target/artemis/bindings</bindings-directory>
+        <journal-directory>./target/artemis/journal</journal-directory>
+        
<large-messages-directory>./target/artemis/large-messages</large-messages-directory>
+
+        <connectors>
+            <connector name="activemq">tcp://localhost:61616</connector>
+        </connectors>
+        <acceptors>
+            <acceptor name="activemq">tcp://localhost:61616</acceptor>
+        </acceptors>
+
+        <max-disk-usage>-1</max-disk-usage>
+        <security-enabled>false</security-enabled>
+
+        <addresses>
+            <address name="test-jms">
+                <anycast>
+                    <queue name="test-jms"/>
+                </anycast>
+            </address>
+        </addresses>
+    </core>
+</configuration>

Reply via email to