davsclaus commented on code in PR #57: URL: https://github.com/apache/camel-spring-boot-examples/pull/57#discussion_r868398608
########## spring-boot-jta-jpa/src/main/java/sample/camel/CamelRoutes.java: ########## @@ -0,0 +1,66 @@ +/* + * 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 sample.camel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class CamelRoutes extends RouteBuilder { + @Value("${camel.servlet.mapping.context-path}") + public String contextPath; + + @Override + public void configure() { + restConfiguration() + .contextPath(contextPath.substring(0, contextPath.length() - 2)); Review Comment: Can you add code comment why you - 2 ########## spring-boot-jta-jpa/src/main/resources/spring-camel.xml: ########## @@ -0,0 +1,113 @@ +<?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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + <bean id="auditLog" class="sample.camel.AuditLog"/> + <bean id="transactionManagerImple" + class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"/> + <bean id="userTransactionImple" class="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple"/> + <bean id="recoveryManagerFactory" class="sample.camel.RMFactory"/> + <bean id="recoveryManager" factory-bean="recoveryManagerFactory" factory-method="createInstance"/> + <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> + <property name="transactionManager" ref="transactionManagerImple"/> + <property name="userTransaction" ref="userTransactionImple"/> + </bean> + <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy"> + <property name="transactionManager" ref="jtaTransactionManager"/> + <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/> + </bean> + + <bean id="jtaDataSource" class="com.mysql.cj.jdbc.MysqlXADataSource"> + <property name="url" value="jdbc:mysql://localhost:3306/testdb"/> + <property name="user" value="admin"/> + <property name="password" value="admin"/> + </bean> + + <!-- Pooled JTA aware data source --> + <bean id="pooledJtaDataSource" class="org.apache.commons.dbcp2.managed.BasicManagedDataSource"> + <property name="transactionManager" ref="transactionManagerImple"/> + <property name="xaDataSourceInstance" ref="jtaDataSource"/> + <property name="initialSize" value="5"/> + <property name="maxIdle" value="5"/> + </bean> + + <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> + <property name="packagesToScan" value="sample.camel"/> + <property name="jtaDataSource" ref="pooledJtaDataSource"/> + <property name="persistenceUnitName" value="camel"/> + <property name="jpaDialect"> + <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/> + </property> + <property name="jpaVendorAdapter"> + <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> + <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/> + </bean> + </property> + <property name="jpaProperties"> + <props> + <prop key="hibernate.hbm2ddl.auto">none</prop> + <prop key="hibernate.id.new_generator_mappings">false</prop> + <prop key="hibernate.transaction.coordinator_class">jta</prop> + <prop key="hibernate.transaction.jta.platform"> + org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform + </prop> + <prop key="hibernate.show_sql">false</prop> + <prop key="hibernate.format_sql">true"</prop> + </props> + </property> + </bean> + + <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent"> + <property name="transactionManager" ref="jtaTransactionManager"/> + <property name="entityManagerFactory" ref="entityManagerFactory"/> + <property name="joinTransaction" value="true"/> + <property name="sharedEntityManager" value="false"/> + </bean> + + <bean id="jtaConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory"> + <constructor-arg value="tcp://localhost:61616"/> + <constructor-arg value="admin"/> + <constructor-arg value="admin"/> + </bean> + + <!-- Pooled JTA aware connection factory --> + <bean id="pooledJtaConnectionFactory" class="org.messaginghub.pooled.jms.JmsPoolXAConnectionFactory"> + <property name="transactionManager" ref="transactionManagerImple"/> + <property name="connectionFactory" ref="jtaConnectionFactory"/> + <property name="maxConnections" value="1"/> + <property name="maxSessionsPerConnection" value="100"/> + <property name="useAnonymousProducers" value="false"/> + </bean> + + <bean id="jms" class="org.apache.camel.component.jms.JmsComponent"> + <property name="configuration"> + <bean class="org.apache.camel.component.jms.JmsConfiguration"> + <property name="transactionManager" ref="jtaTransactionManager"/> + <property name="connectionFactory" ref="pooledJtaConnectionFactory"/> + <!-- disable local transactions as JTA TM will take care of enrolling --> + <property name="transacted" value="false"/> + <!-- caching does not work with distributed transactions --> + <property name="cacheLevelName" value="CACHE_NONE"/> + <property name="maxConcurrentConsumers" value="1"/> + <property name="testConnectionOnStartup" value="true"/> + </bean> + </property> + </bean> +</beans> Review Comment: Its a bit sad or scary that it takes 100+ lines of spring bean configuration to setup JTA with a database and JMS :( ########## spring-boot-jta-jpa/src/main/java/sample/camel/CamelRoutes.java: ########## @@ -0,0 +1,66 @@ +/* + * 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 sample.camel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class CamelRoutes extends RouteBuilder { + @Value("${camel.servlet.mapping.context-path}") + public String contextPath; + + @Override + public void configure() { + restConfiguration() + .contextPath(contextPath.substring(0, contextPath.length() - 2)); + + 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:it.fvaleri.integ.AuditLog?namedQuery=getAuditLog") Review Comment: The package name should likely be sample.camel ########## spring-boot-jta-jpa/src/main/java/sample/camel/CamelRoutes.java: ########## @@ -0,0 +1,66 @@ +/* + * 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 sample.camel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class CamelRoutes extends RouteBuilder { + @Value("${camel.servlet.mapping.context-path}") + public String contextPath; + + @Override + public void configure() { + restConfiguration() + .contextPath(contextPath.substring(0, contextPath.length() - 2)); + + 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:it.fvaleri.integ.AuditLog?namedQuery=getAuditLog") + .convertBodyTo(String.class); + + from("direct:trans") + .transacted() + .setBody(simple("${headers.message}")) + .to("bean:auditLog?method=createAuditLog(${body})") + .to("jpa:it.fvaleri.integ.AuditLog") Review Comment: Same here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
