You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by afant <al...@gmail.com> on 2013/06/18 20:01:45 UTC

Retry connection on broker start when database is unavailable

I am using ActiveMQ 5.7  with JDBC master/slave (mySQL) configuration. 
Additionally, I have configured HA to use jdbcPersistenceAdapter that uses
the the database locker by default.  Currently, by design the broker will
not start unless the broker can connect to the database.  If the broker is
started before the database is started, I get the following Runtime
exception, ERROR failed to start Apache ActiveMQ. Reason:
java.io.IOException: Communication link failure.

Our project routinely does patch upgrades to it's servers, and we have no
control over the order in which our ActiveMQ brokers and mysql databases
(jdbcPersistenceAdapters) are started.  The desired behavior would be to
start the broker (no RuntimeException), and allow the broker to retry
(multiple times) the connection to the database.  Is this feature available
in this release?  If so, could you provide me with the documentation to set
this up?



--
View this message in context: http://activemq.2283324.n4.nabble.com/Retry-connection-on-broker-start-when-database-is-unavailable-tp4668329.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Retry connection on broker start when database is unavailable

Posted by Christian Posta <ch...@gmail.com>.
Looked at the code. Looks like the current impl expects the locker to have
achieved the lock at least once. The functionality will then restart the
broker when it loses the lock.

I guess you could implement this blocking/retry-mechanism in your
datasource#getConnection()....So when activemq tries to start up the
persistence adapter it will block there when it tries to aquire a
connection instead of just fail?

If this doesn't suit you, please open a JIRA. we can possibly broaden the
scope of retry mechanisms to include not only keepAlive scenarios.




On Mon, Jun 24, 2013 at 12:35 PM, afant <al...@gmail.com> wrote:

> I just tried the 5.9 nightly snapshot.  On my broker I set
> restartAllowed="true".  Then, I tried to start the broker while the
> database
> was down, and the broker still failed to start.  I saw a restart was
> triggered by the default IO exception handler, and since the database was
> still down a RuntimeException was thrown ("Failed to execute start task.
> Reason: java.lang.IllegalStateException: BeanFactory not initialized or
> already closed - call 'refresh' before accessing beans via the
> ApplicationContext....)
>
> The desired behavior would be to just continue to retry the database
> connection.  I even tried adding retryconnection parameters to mysql url
> ex:
> autoReconnect=true&amp;maxReconnects=2147483647.
>
> Thanks,
> Allen
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Retry-connection-on-broker-start-when-database-is-unavailable-tp4668329p4668528.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: Retry connection on broker start when database is unavailable

Posted by Paul Gale <pa...@gmail.com>.
Would it make a difference if you used the JDBCIOExceptionHandler instead
of the default one perhaps? Just a thought.

<broker ioExceptionHandler="#handler_id">
</broker>

<!-- dummy values -->
<bean id="handler_id"
class="org.apache.activemq.store.jdbc.JDBCIOExceptionHandler">
  <property name="ignoreSQLExceptions" value="true" />
  <property name="ignoreAllErrors" value="false" />
  <property name="stopStartConnectors" value="true"/>
</bean>


On Mon, Jun 24, 2013 at 12:35 PM, afant <al...@gmail.com> wrote:

> I just tried the 5.9 nightly snapshot.  On my broker I set
> restartAllowed="true".  Then, I tried to start the broker while the
> database
> was down, and the broker still failed to start.  I saw a restart was
> triggered by the default IO exception handler, and since the database was
> still down a RuntimeException was thrown ("Failed to execute start task.
> Reason: java.lang.IllegalStateException: BeanFactory not initialized or
> already closed - call 'refresh' before accessing beans via the
> ApplicationContext....)
>
> The desired behavior would be to just continue to retry the database
> connection.  I even tried adding retryconnection parameters to mysql url
> ex:
> autoReconnect=true&amp;maxReconnects=2147483647.
>
> Thanks,
> Allen
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Retry-connection-on-broker-start-when-database-is-unavailable-tp4668329p4668528.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Retry connection on broker start when database is unavailable

Posted by afant <al...@gmail.com>.
I just tried the 5.9 nightly snapshot.  On my broker I set
restartAllowed="true".  Then, I tried to start the broker while the database
was down, and the broker still failed to start.  I saw a restart was
triggered by the default IO exception handler, and since the database was
still down a RuntimeException was thrown ("Failed to execute start task. 
Reason: java.lang.IllegalStateException: BeanFactory not initialized or
already closed - call 'refresh' before accessing beans via the
ApplicationContext....)

The desired behavior would be to just continue to retry the database
connection.  I even tried adding retryconnection parameters to mysql url ex:
autoReconnect=true&amp;maxReconnects=2147483647.

Thanks,
Allen



--
View this message in context: http://activemq.2283324.n4.nabble.com/Retry-connection-on-broker-start-when-database-is-unavailable-tp4668329p4668528.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Retry connection on broker start when database is unavailable

Posted by Christian Posta <ch...@gmail.com>.
Can you give a try to one of the nightly snapshots? This should be resolved
in 5.9:

https://issues.apache.org/jira/browse/AMQ-4526



On Tue, Jun 18, 2013 at 2:01 PM, afant <al...@gmail.com> wrote:

> I am using ActiveMQ 5.7  with JDBC master/slave (mySQL) configuration.
> Additionally, I have configured HA to use jdbcPersistenceAdapter that uses
> the the database locker by default.  Currently, by design the broker will
> not start unless the broker can connect to the database.  If the broker is
> started before the database is started, I get the following Runtime
> exception, ERROR failed to start Apache ActiveMQ. Reason:
> java.io.IOException: Communication link failure.
>
> Our project routinely does patch upgrades to it's servers, and we have no
> control over the order in which our ActiveMQ brokers and mysql databases
> (jdbcPersistenceAdapters) are started.  The desired behavior would be to
> start the broker (no RuntimeException), and allow the broker to retry
> (multiple times) the connection to the database.  Is this feature available
> in this release?  If so, could you provide me with the documentation to set
> this up?
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Retry-connection-on-broker-start-when-database-is-unavailable-tp4668329.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta