You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Patrick Valsecchi <pa...@camptocamp.com> on 2016/01/04 12:23:06 UTC

JPA consumer reconnection

Hi,

I'm using camel version 2.16.1 with openjdk 1.7, hibernate 5.0.3 and
postgres JDBC 9.4-1205.

I have a JPA consumer configured like that:
<route id="queue">
  <from
uri="jpa:ch.xxx.ExploitationQueue?consumeLockEntity=false&amp;consumer.delay=1000&amp;maxMessagesPerPoll=1&amp;consumer.query=from
ch.xxx.ExploitationQueue order by id"/>
  ...
</route>

JPA is configured like that:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="persistenceUnit"/>
</bean>
<bean id="jpaTxManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="transactionManager" ref="jpaTxManager"/>
</bean>

And my persistence.xml looks like that:
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
    <properties>
        <property name="javax.persistence.jdbc.driver"
value="org.postgresql.Driver" />
        <property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://db/ZZZZZ" />
        <property name="javax.persistence.jdbc.user" value="www-data" />
        <property name="javax.persistence.jdbc.password" value="XXXXXX" />
        <property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQL9Dialect" />
        <property name="hibernate.connection.autoReconnect" value="true" />
        <property name="hibernate.connection.autoReconnectForPools"
value="true" />

        <property name="hibernate.connection.provider_class"
value="org.hibernate.connection.C3P0ConnectionProvider" />
        <property name="hibernate.c3p0.max_size" value="10" />
        <property name="hibernate.c3p0.min_size" value="1" />
        <property name="hibernate.c3p0.acquire_increment" value="1" />
        <property name="hibernate.c3p0.idle_test_period" value="300" />
        <property name="hibernate.c3p0.max_statements" value="0" />
        <property name="hibernate.c3p0.timeout" value="100" />
        <property name="hibernate.c3p0.validate" value="true" />
        <property name="hibernate.c3p0.testConnectionOnCheckout"
value="true" />
        <property name="hibernate.c3p0.breakAfterAcquireFailure"
value="false" />
    </properties>
</persistence-unit>

In a nominal case, everything works fine.

If I bounce my database server Camel doesn't reconnect to the database and
I have logs like that:
11:17:49.756 [Camel (xxx) thread #0 - jpa://ch.xxx.ExploitationQueue] DEBUG
o.h.e.t.internal.TransactionImpl - begin
11:17:49.761 [Camel (xxx) thread #0 - jpa://ch.xxx.ExploitationQueue] DEBUG
org.hibernate.SQL - select exploitati0_.id as id1_0_, exploitati0_.query as
query2_0_, exploitati0_.uuid as uuid3_0_ from exploitation_queue
exploitati0_ order by exploitati0_.id
04-Jan-2016 11:17:49.761 WARNING [Camel (xxx) thread #0 -
jpa://ch.xxx.ExploitationQueue]
com.mchange.v2.c3p0.impl.NewPooledConnection.handleThrowable [c3p0] A
PooledConnection that has already signalled a Connection error is still in
use!
04-Jan-2016 11:17:49.762 WARNING [Camel (xxx) thread #0 -
jpa://ch.xxx.ExploitationQueue]
com.mchange.v2.c3p0.impl.NewPooledConnection.handleThrowable [c3p0] Another
error has occurred [ org.postgresql.util.PSQLException: This connection has
been closed. ] which will not be reported to listeners!
 org.postgresql.util.PSQLException: This connection has been closed.

So looks like the connection pool is not re-connecting the DB because the
connection is still in use. I've looked all over the place at every level,
did a lot of tunning and found no solution to that.

Anybody have an idea on how to have JPA reconnect to the DB automatically?

Thanks.

Re: JPA consumer reconnection

Posted by Patrick Valsecchi <pa...@camptocamp.com>.
I've tried several connection pools with no success. The problem is that
JPA is keeping the connection, I guess.

I've solved my problem by switching to the hibernate Camel component and
reconnection works fine with C3P0.

On Tue, Jan 5, 2016 at 10:06 PM, SaurabhNayar <Na...@gmail.com>
wrote:

> That's not good from c3p0. You can try a different connection pool
> altogether.
>
> Apache DBCP is compatible with Hibernate
> http://commons.apache.org/proper/commons-dbcp/
>
> Here are some more details on Hibernate connection pooling:
> http://www.informit.com/articles/article.aspx?p=353736&seqNum=4
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/JPA-consumer-reconnection-tp5775721p5775856.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: JPA consumer reconnection

Posted by SaurabhNayar <Na...@gmail.com>.
That's not good from c3p0. You can try a different connection pool
altogether. 

Apache DBCP is compatible with Hibernate
http://commons.apache.org/proper/commons-dbcp/

Here are some more details on Hibernate connection pooling:
http://www.informit.com/articles/article.aspx?p=353736&seqNum=4



--
View this message in context: http://camel.465427.n5.nabble.com/JPA-consumer-reconnection-tp5775721p5775856.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JPA consumer reconnection

Posted by Patrick Valsecchi <pa...@camptocamp.com>.
Nayar,

I've configured c3p0 to do all that and the logs at the beginning seems to
confirm that, but since the broken connection is still holded, it cannot do
anything. Hence this message, I guess:
com.mchange.v2.c3p0.impl.NewPooledConnection.handleThrowable [c3p0] A
PooledConnection that has already signalled a Connection error is still in
use!

I've configured idleConnectionTestPeriod and preferredTestQuery defaults to
the listing of the tables.

Thanks.

On Mon, Jan 4, 2016 at 8:20 PM, SaurabhNayar <Na...@gmail.com>
wrote:

> Please refer to:
>
>
> http://www.mchange.com/projects/c3p0/index.html#configuring_connection_testing
> <
> http://www.mchange.com/projects/c3p0/index.html#configuring_connection_testing
> >
>
> You can use:
> /idleConnectionTestPeriod
> preferredTestQuery/
>
> parameters to make the c3p0 connection pool reconnect with DB.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/JPA-consumer-reconnection-tp5775721p5775767.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: JPA consumer reconnection

Posted by SaurabhNayar <Na...@gmail.com>.
Please refer to:

http://www.mchange.com/projects/c3p0/index.html#configuring_connection_testing
<http://www.mchange.com/projects/c3p0/index.html#configuring_connection_testing
>  

You can use:
/idleConnectionTestPeriod
preferredTestQuery/

parameters to make the c3p0 connection pool reconnect with DB.



--
View this message in context: http://camel.465427.n5.nabble.com/JPA-consumer-reconnection-tp5775721p5775767.html
Sent from the Camel - Users mailing list archive at Nabble.com.