[
https://issues.apache.org/activemq/browse/AMQ-2245?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Raphaƫl Ramirez updated AMQ-2245:
---------------------------------
Attachment: ActiveMQThreadBrokerFactory.java
I would like to do the following with an Master-slave with database lock
configuration :
- if a database problem occurs (loss of connection, etc.)
- the master looses the database lock : ??"No longer able to keep the exclusive
lock so giving up being a master"?? and a slave become the new master as usual
- but instead of shutting the broker down completely, I'm trying to make it
become a slave (able to become a master again)
I use the attached ActiveMQThreadBrokerFactory in Spring as following (also see
AMQ-1273) : \\
\\
{code:xml|title=SpringContext.xml|borderStyle=solid}
<bean id="brokerFactory"
class="app.messaging.ActiveMQThreadBrokerFactory">
<property name="brokerService" ref="brokerService"/><!-- start
must be false on this broker -->
<property name="exceptionHandler" ref="exceptionHandler"/>
</bean>
<amq:broker useJmx="true" persistent="true" brokerName="broker2"
id="brokerService" start="false">
<amq:managementContext>
<amq:managementContext useMBeanServer="true" createMBeanServer="false"
createConnector="false"/> <!-- use the JVM MBean server -->
</amq:managementContext>
<amq:persistenceAdapter>
<amq:jdbcPersistenceAdapter dataSource="#persistenceDataSource"
createTablesOnStartup="true" useDatabaseLock="true" />
</amq:persistenceAdapter>
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:50000" />
<amq:transportConnector name="stomp"
uri="stomp://localhost:50001" />
</amq:transportConnectors>
</amq:broker>
<bean id="persistenceDataSource" class="...." init-method="init"
destroy-method="close">
....
</bean>
<!-- modified exception handler to avoid logging "Lock wait timeout
exceeded" messages (normal slave behaviour) -->
<bean id="exceptionHandler" class="app.messaging.LockExceptionHandler"/>
{code}
\\
With this configuration, the master->slave behavior works (looping to acquire
the lock). But when the lock is obtained again, it happens that the broker is
actually replaced by an ErrorBroker (replaced during the previous stop):
{code:title=BrokerService.java|borderStyle=solid}
protected Broker createBroker() throws Exception {
...
public void stop() throws Exception {
old = this.next.getAndSet(new ErrorBroker("Broker has been
stopped: " + this) {
// Just ignore additional stop actions.
public void stop() throws Exception {
}
});
old.stop();
}
...
{code}
So I get the following stacktrace when nowMasterBroker is called :
{panel}
INFO org.apache.activemq.store.jdbc.DefaultDatabaseLocker | Becoming the
master on dataSource: app.db.configurabledbcpdatasou...@deeebd
ERROR org.apache.activemq.broker.BrokerService | Failed to start ActiveMQ JMS
Message Broker. Reason: org.apache.activemq.broker.BrokerStoppedException:
Broker has been stopped: org.apache.activemq.broker.brokerservic...@1f489d9
org.apache.activemq.broker.BrokerStoppedException: Broker has been stopped:
org.apache.activemq.broker.brokerservic...@1f489d9
at
org.apache.activemq.broker.ErrorBroker.nowMasterBroker(ErrorBroker.java:297)
at
org.apache.activemq.broker.MutableBrokerFilter.nowMasterBroker(MutableBrokerFilter.java:307)
at
org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.start(JDBCPersistenceAdapter.java:208)
at
org.apache.activemq.broker.BrokerService.start(BrokerService.java:449)
at
org.apache.activemq.broker.BrokerService.start(BrokerService.java:420)
at
app.messaging.ActiveMQThreadBrokerFactory$BrokerThread.run(ActiveMQThreadBrokerFactory.java:64)
INFO org.apache.activemq.broker.BrokerService | ActiveMQ Message Broker
(broker2, ID:PC030-52124-1958729374192-0:0) is shutting down
INFO org.apache.activemq.broker.TransportConnector | Connector
tcp://localhost:50001 Stopped
INFO org.apache.activemq.broker.TransportConnector | Connector stomp Stopped
INFO org.apache.activemq.broker.BrokerService | ActiveMQ JMS Message Broker
(broker2, ID:PC030-52124-1958729374192-0:0) stopped
ERROR app.messaging.ActiveMQThreadBrokerFactory | Init brokerService error.
Will try again in 10000 ms
{panel}
I assume that checking ??forceStart?? in ??BrokerService.getBroker()?? may help
by calling again ??createBroker()?? for an existing (non null) broker.
(Another thing is that with my configuration, setting
??lockAcquireSleepInterval?? in ??<amq:jdbcPersistenceAdapter/>?? in the Spring
context has no effect (the default value is always used). This is why I have to
set it (twice) in ??ActiveMQThreadBrokerFactory.java??.)
> Allow restart of embedded broker
> --------------------------------
>
> Key: AMQ-2245
> URL: https://issues.apache.org/activemq/browse/AMQ-2245
> Project: ActiveMQ
> Issue Type: Improvement
> Affects Versions: 5.2.0
> Reporter: Dejan Bosanac
> Assignee: Dejan Bosanac
> Fix For: 5.3.0
>
> Attachments: ActiveMQThreadBrokerFactory.java
>
>
> Currently we don't allow restarting the stopped broker and instead developers
> need to create another instance of the broker and start it. Usually this is a
> desired behavior and should remain a default one. But we should provide an
> option to people wanting to start stopped brokers. The proposed enhancement
> will introduce
> {code}
> public void start(boolean force);
> {code}
> method, which will force the broker to start.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.