No persistence providers available for "transactions-optional" - google-app-engine

I'm having this error in my AppEngine project:
javax.persistence.PersistenceException: No persistence providers available for "transactions-optional" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:180)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70)
jdoconfig.xml
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.PersistenceManagerFactoryClass"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.appengine.singletonPMFForName" value="true"/>
</persistence-manager-factory>
</jdoconfig>
Its really weird since in my jdoconfig.xml there is this "transactions-optional"

Obviously JPA (which you use to get an EMF) doesn't use "jdoconfig.xml" (which is used by JDO). JPA uses "persistence.xml". Suggest you decide which API you're using before going further

Related

Apache Artemis - Apache Camel threaded consumer gets slow over time

I am running Apache Artemis Broker 2.14.0. Below is the consumer connection configuration:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="com.test.CustomProcessBean" id="CustomProcessBean" scope="prototype"/>
<bean id="jmsCF" class="org.apache.qpid.jms.JmsConnectionFactory">
<property name="remoteURI" value="ampq://myhost:5672"/>
</bean>
<bean id="jmsPooledCF" class="org.messaginghub.pooled.jms.JmsPoolConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="3" />
<property name="connectionFactory" ref="jmsCF" />
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsPooledCF" />
<property name="concurrentConsumers" value="5" />
<property name="maxConcurrentConsumers" value="10" />
</bean>
<bean id="jms" class="org.apache.camel.component.amqp.AMQPComponent">
<property name="configuration" ref="jmsConfig" />
<property name="transacted" value="true" />
</bean>
<bean id="errHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
<property name="deadLetterUri" value="jms:queue:customDLQ"/>
<property name="redeliveryPolicy" ref="customRedeliveryPolicyConfig"/>
</bean>
<bean id="customRedeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy">
<property name="maximumRedeliveries" value="3"/>
<property name="redeliveryDelay" value="8000"/>
</bean>
<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
<endpoint id="etams" uri="jms:queue:test-queue" />
<route errorHandlerRef="errHandler" >
<from uri="ref:etams"/>
<convertBodyTo type="java.lang.String" />
<threads id="threadedprocess" maxQueueSize="5" poolSize="5" maxPoolSize="5" customId="true" >
<bean ref="CustomProcessBean" method="processMessage"/>
</threads>
</route>
</camelContext>
</beans>
To begin with the route was processing ~100 message-per-second. Over time (~6 hrs) it dropped to ~25 messages-per-second.
From the "Consumers" tab in the Artemis web console I noticed each session is closed and created often.
From the broker side we had provided enough memory 12G. The broker runs with persistence enabled, and the incoming message size are less than 5kb.
Does the Camel threads try to create more session over time? Is this an anti-pattern? Is this the reason for consumer to process the messages slow overtime? When I don't use the Camel threads in the configuration (i.e. just <bean ref="CustomProcessBean ...>) I noticed the session ID created are NOT changing. This might be totally based on the use case, but does re-creating the sessions cause performance stress on broker?
I have faced the same issue and solved it by setting cacheLevelName option in the JMS endpoint to CACHE_CONSUMER. By enabling the transacted option, you end up setting cache level to CACHE_NONE.
This section will explain you better: JMS Component - TRANSACTIONS AND CACHE LEVELS

XA transactions Support with JBoss Widlfly 10, camel-2.15.3, and Red Hat AMQ 7.2

Problem Statement: In "JTA/XA" mode when messages are consumed from "Source-Q" using camel and after performing the business logic(successful processing without any error or exception) unable to send the response back to "Destination-Q".
Enabled "camel" logging but no "errors/exceptions" are found for the "Destination- end point".
Used Tech Stack:
JBoss Wildfly 10 (on Windows)
activemq-rar-5.11.0.redhat-630356.rar (latest as per https://maven.repository.redhat.com/ga/org/apache/activemq/activemq-rar/)
camel-2.15.3
Red Hat AMQ 7.2 (Linux). Used "artemis create" to create an instance with default configurations.
"Resource adaptor approach" is followed with JBoss Wildfly 10 to integrate with Red Hat MQ 7.2.
Snippets from JBoss Wildfly 10 - "standalone.xml" configurations are provided below:
<subsystem xmlns="urn:jboss:domain:resource-adapters:4.0">
<resource-adapters>
<resource-adapter id="activemq">
<archive>
activemq-rar-5.11.0.redhat-630356.rar
</archive>
<transaction-support>XATransaction</transaction-support>
<config-property name="ServerUrl">
tcp://redhatamqhostname:61616?jms.redeliveryPolicy.maximumRedeliveries=2
</config-property>
<config-property name="UserName">
defaultUser
</config-property>
<config-property name="InitialRedeliveryDelay">
1000
</config-property>
<config-property name="Password">
defaultPassword
</config-property>
<connection-definitions>
<connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/XAconnectionFactory" enabled="true" use-java-context="true" pool-name="ConnectionFactory">
<xa-pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>false</prefill>
<is-same-rm-override>false</is-same-rm-override>
</xa-pool>
</connection-definition>
</connection-definitions>
</resource-adapter>
</resource-adapters>
</subsystem>
Snippets from "camel-context" configurations are provided below:
<bean id="JBOSSRMQ" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration">
<bean class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="connectionFactory" />
<property name="transactionManager" ref="transactionManager" />
<property name="transacted" value="false" />
<property name="concurrentConsumers" value="1" />
<property name="deliveryPersistent" value="true" />
<property name="requestTimeout" value="10000" />
<property name="cacheLevelName" value="CACHE_NONE" />
</bean>
</property>
</bean>
<jee:jndi-lookup id="connectionFactory" jndi-name="java:/XAconnectionFactory"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
Any ideas/thoughts to make it work? Thanks in advance!

Using xa transactions in Karaf

I'm trying to create a xa transaction between postgres (using pax-jdbc to set up xa datasource) and activemq in karaf, using blueprint and camel.
The setup is the following: I have a camel route which receives a jms message, does some database updates, and then sends a jms message to another queue. This other queue then reads the updated records.
The problem is that the second queue is reading the old data instead of getting the updated data.
I believe the cause is that JMS transaction is being "released" first, and the database has not commited the changes yet.
If I put a Thread.sleep(1000) on the second queue, I always read the correct data. Also, I believe the transaction is working fine, if I throw an exception in the camel route, I see no changes in the database, and the jms message does not get sent, proving they are working together.
Here's my blueprint with the jta configs and camel route:
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v2.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/xmlns/transactions/v2.0.0 http://aries.apache.org/schemas/transaction/transactionv20.xsd">
<tx:enable/>
<bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
<property name="transactionManager" ref="jtaTxManager" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="resourceName" value="activemq.localhost" />
</bean>
<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="0"/>
</bean>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="$ext{brokerUrl}"/>
<property name="userName" value="karaf"/>
<property name="password" value="karaf"/>
<property name="redeliveryPolicy" ref="redeliveryPolicy"/>
</bean>
<bean id="jmsXaPoolConnectionFactory" class="org.apache.activemq.pool.JcaPooledConnectionFactory">
<property name="name" value="activemq.default"/>
<property name="maxConnections" value="4"/>
<property name="transactionManager" ref="jtaTxManager"/>
<property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
<!-- define the activemq Camel component so we can integrate with the AMQ broker -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<!-- due to a bug in activemq-camel we must configure using a nested configuration bean -->
<property name="configuration">
<bean class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsXaPoolConnectionFactory"/>
<!-- JTA transaction manager (Spring interface to Aries-TM) -->
<property name="transactionManager" ref="springJtaTxManager"/>
<!-- IMPORTANT: We set local transactions to false, because the JtaTransactionManager
will take care of enrolling the XA JMS Connection when needed. -->
<property name="transacted" value="false"/>
<!-- IMPORTANT: and disable cache level as the JtaTransactionManager needs to control the consumers
from its JcaPooledConnectionFactory -->
<property name="cacheLevelName" value="CACHE_NONE"/>
</bean>
</property>
</bean>
<reference id="jtaTxManager" interface="org.apache.geronimo.transaction.manager.RecoverableTransactionManager"/>
<reference id="springJtaTxManager" interface="org.springframework.transaction.PlatformTransactionManager"/>
<bean id="required" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="springJtaTxManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint" id="om-bstask-context" useMDCLogging="true">
<route id="notificationConsumer">
<from uri="activemq:queue:incomingNotification"/>
<transacted ref="required"/>
<doTry>
<!-- execute some bd updates -->
<to uri="activemq:anotherQueue"/>
<doCatch>
<exception>java.lang.Exception</exception>
<handled>
<constant>false</constant>
</handled>
<bean beanType="xxxx.MessagingUtil"
method="logErrorMessage(${headers.JMSXDeliveryCount}, ${headers.om_txid}, 'incomingNotification', ${exception})"/>
</doCatch>
<doFinally>
</doFinally>
</doTry>
</route>
</camelContext>
</blueprint>
Do I have something wrong with my setup? Or what could explain this behavior?
PS I got the config from https://github.com/camelinaction/camelinaction2/blob/master/chapter12/xa-karaf/src/main/resources/OSGI-INF/blueprint/camel-context.xml

DatastoreJDOPersistenceManagerFactory class not found exception when configuring JDO on Appengine

I am trying to configure JDO on Appengine but every time I try to persist something I get an
java.lang.ClassNotFoundException: org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory
Searching for this error I only got that I could have an error in my jdoconfig.xml
But I explicitly declare that I want to use this class my jdoconfig.xml, which I posted below.
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
</persistence-manager-factory>
</jdoconfig>
decide if you are using GAE JDO plugin v1.0 (JDO2.x) or GAE JDO plugin v2.0 (JDO3.0) which kinda decides which jars you have in the classpath, and hence what entries you put in your jdoconfig.xml

Appengine jdoconfig.xml for local database

Has anyone successfully configured JDO datanucleus default to google app engine to work on a local database?
Why am I always getting an error in jdoconfig.xml when I have specified the property "datanucleus.storeManagerType" with value "rdbms." at the end part.
I tried googling but seems no luck.
Caused by: org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "rdbms". Please make sure you have specified "datanucleus.storeManagerType" correctly and that all relevant plugins are in the CLASSPATH
<persistence-manager-factory name="postgresql">
<property name="datanucleus.mapping.Schema" value="jdo"/>
<property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="datanucleus.ConnectionDriverName" value="org.postgresql.Driver"/>
<property name="datanucleus.ConnectionURL" value="jdbc:postgresql://localhost:5432/jdo"/>
<property name="datanucleus.ConnectionUserName" value="jdo"/>
<property name="datanucleus.ConnectionPassword" value="jdo"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.autoStartMechanism" value="None"/>
<property name="datanucleus.autoCreateSchema" value="true"/>
<property name="datanucleus.validateTables" value="true"/>
<property name="datanucleus.validateConstraints" value="true"/>
<property name="datanucleus.validateColumns" value="true"/>
<property name="datanucleus.DetachAllOnCommit" value="true"/>
<property name="datanucleus.maxFetchDepth" value="1"/>
<property name="datanucleus.storeManagerType" value="rdbms"/>
code for PMF.java
private static final PersistenceManagerFactory pmfInstance =
JDOHelper.getPersistenceManagerFactory("postgresql");
I remember fixing this by including datanucleus-rdbms-X.Y.Z.jar in my WEB-INF/lib
When using another datastore aside from the default app-engine sdk's "transaction-optional" datastore, you need to use another web application container such as apache-tomcat or jetty in order for the rdbms driver classes (ie, postgresql.jar-org.postgresql.Driver, mysql.jar com.mysql.jdbc.Driver) to work since google app engine inhibits your application to use the java.net.socket.* which is used by the database drivers

Resources