ActiveMQ not reconnecting to SQLServer when using the net.sourceforge.jtds.jdbc.Driver
Issue
- When using SQLServer as the persistence store for ActiveMQ the connection to the database is not reestablished when using the net.sourceforge.jtds.jdbc.Driver.
To prevent the broker from shutting down if the database becomes unavailable, ActiveMQ has been configured with the ioExceptionHandler as follows:
<ioExceptionHandler>
<jDBCIOExceptionHandler stopStartConnectors="true" />
</ioExceptionHandler>
<persistenceAdapter>
<jdbcPersistenceAdapter dataDirectory="${data}" dataSource="#sql-ds">
<locker>
<lease-database-locker lockAcquireSleepInterval="30000"/>
</locker>
</jdbcPersistenceAdapter>
</persistenceAdapter>
This will prevent the broker from shutting down, as the jdbcIOExceptionHandler has been configured which sets the stopStartConnectors=true.
When the database is shutdown the following logging will be seen to indicate the broker will wait for a successful checkpoint before restarting the connectors:
13:11:30,638 | INFO | ost IO exception | DefaultIOExceptionHandler | 114 - org.apache.activemq.activemq-osgi - 5.8.0.redhat-60024 | waiting for broker persistence adapter checkpoint to succeed before restarting transports
However, once the database is restarted the following is seen:
08:42:48,360 | WARN | start transports | LeaseDatabaseLocker | 114 - org.apache.activemq.activemq-osgi - 5.8.0.redhat-60065 | amq, failed to update lease: java.sql.SQLException: Network error IOException: Connection refused
java.sql.SQLException: Network error IOException: Connection refused
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:434)[236:wrap_mvn_net.sourceforge.jtds_jtds_1.3.0:0]
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:183)[236:wrap_mvn_net.sourceforge.jtds_jtds_1.3.0:0]
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)[235:org.apache.servicemix.bundles.commons-dbcp:1.4.0.3]
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)[235:org.apache.servicemix.bundles.commons-dbcp:1.4.0.3]
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188)[112:org.apache.commons.pool:1.6.0]
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)[235:org.apache.servicemix.bundles.commons-dbcp:1.4.0.3]
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)[235:org.apache.servicemix.bundles.commons-dbcp:1.4.0.3]
at org.apache.activemq.store.jdbc.LeaseDatabaseLocker.getConnection(LeaseDatabaseLocker.java:127)[114:org.apache.activemq.activemq-osgi:5.8.0.redhat-60065]
at org.apache.activemq.store.jdbc.LeaseDatabaseLocker.keepAlive(LeaseDatabaseLocker.java:228)[114:org.apache.activemq.activemq-osgi:5.8.0.redhat-60065]
at org.apache.activemq.store.jdbc.JDBCIOExceptionHandler.hasLockOwnership(JDBCIOExceptionHandler.java:47)[114:org.apache.activemq.activemq-osgi:5.8.0.redhat-60065]
at org.apache.activemq.util.DefaultIOExceptionHandler$1$1.run(DefaultIOExceptionHandler.java:98)[114:org.apache.activemq.activemq-osgi:5.8.0.redhat-60065]
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)[:1.7.0_60]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)[:1.7.0_60]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)[:1.7.0_60]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)[:1.7.0_60]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.7.0_60]
at java.net.Socket.connect(Socket.java:579)[:1.7.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_60]
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:300)[236:wrap_mvn_net.sourceforge.jtds_jtds_1.3.0:0]
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:253)[236:wrap_mvn_net.sourceforge.jtds_jtds_1.3.0:0]
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:329)[236:wrap_mvn_net.sourceforge.jtds_jtds_1.3.0:0]
... 10 more
The net.sourceforge.jtds.jdbc.Driver never seems to be able to reestablish the connection to the database.
Environment
- JBoss Fuse 6.0
- JBoss Fuse 6.0 R2 P1
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
