You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Albrecht Militzer <am...@web.de> on 2011/01/04 11:26:43 UTC

How to configure Failover in Cluster (maybe Master/Slave?)

Hello everyone,

I have a cluster of tomcats. I use Spring 3. I need to distribute some load
across the nodes. I want to use JMS for that and ActiveMQ for JMS. 

As far as I have read, failover with master/slave should me the way to go
for me. Maybe I am already wrong there?

1) I do not want any node of the cluster to be special in any way. So I do
not want any specific one to be the master always. I would like the nodes to
figure out among themselves which is the master. The others wait for the
master to die. If that happens, one of the slaves becomes the master.

Since I already use Spring, I want to use it to configure embedded brokers.

Question: Can this work? Can I use embedded brokers as described in 1) ?
Some browsing led me to believe embedded brokers should be used for store
and forward only.

I got some of it to work. I can send and receive messages. However, there is
no failover. If I kill the node that is the master. I stop being able to
send messages. No slave seems to become the master. I think I can tell this
via JMX. Jconsole shows me a Broker under the org.apache.activemq-node. The
slave node does not even show a org.apache.activemq-node in JMX.

Question: Should a slave waiting to become a master show this via JMX? If
so, how do I configure this?

2) My Spring application context:
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
	xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
	xsi:schemaLocation="
    http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd
	http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.4.2.xsd">

	<context:annotation-config />
	<context:component-scan base-package="de.jeha" />

	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<property name="jdbcUrl"
		
value="jdbc:mysql://${de.jeha.db.host}:3306/test?autoReconnectForPools=true"
/>
		<property name="user" value="amqtest" />
		<property name="password" value="amqtest" />
		<property name="initialPoolSize" value="1" />
		<property name="minPoolSize" value="1" />
		<property name="maxPoolSize" value="3" />
		<property name="preferredTestQuery" value="SELECT 1;" />
		<property name="idleConnectionTestPeriod" value="300" />
	</bean>

	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
		p:dataSource-ref="dataSource" />

	<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
		p:entityManagerFactory-ref="entityManagerFactory" />

	<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url"
		
value="jdbc:mysql://${de.jeha.db.host}:3306/test_activemq?relaxAutoCommit=true&amp;profileSQL=true"
/> <!-- &amp;profileSQL=true -->

        <property name="username" value="amqtest" />
        <property name="password" value="amqtest" />

		<property name="poolPreparedStatements" value="true" />
	</bean>

	<bean id="derby-ds" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName"
value="org.apache.derby.jdbc.ClientDriver" />
		<property name="url" value="jdbc:derby://localhost:1527/amqtest" />

        <property name="username" value="default" />
        <property name="password" value="default" />

		<property name="poolPreparedStatements" value="true" />
	</bean>

	<amq:broker id="broker" useJmx="true" brokerName="brokerName1">
		<amq:managementContext>
			<amq:managementContext connectorPort="${de.jeha.jmxport}"
jmxDomainName="org.apache.activemq" />
		</amq:managementContext>
		<amq:persistenceAdapter>
			<amq:jdbcPersistenceAdapter dataSource="#derby-ds" useDatabaseLock="true"
createTablesOnStartup="true">
				<amq:statements>
                    <amq:statements lockTableName="ACTIVEMQ_LOCK"
                                    lockCreateStatement="SELECT * FROM
ACTIVEMQ_LOCK FOR UPDATE"
                                    messageTableName="ACTIVEMQ_MSGS"
durableSubAcksTableName="ACTIVEMQ_ACKS"/>
                </amq:statements>
			</amq:jdbcPersistenceAdapter>
		</amq:persistenceAdapter>
		<amq:plugins>
			<amq:statisticsBrokerPlugin />
		</amq:plugins>
		<amq:transportConnectors>
			<amq:transportConnector name="default"
uri="tcp://10.121.123.26:${de.jeha.amq.host.port}" />
		</amq:transportConnectors>
	</amq:broker>

	<amq:queue id="destination" physicalName="amq.test" />

	<amq:connectionFactory id="jmsFactory"
	
brokerURL="failover:(tcp://10.121.123.26:61616,tcp://10.121.123.26:62616)?initialReconnectDelay=100"
/>

	<bean id="jmsTransactionManager"
		class="org.springframework.jms.connection.JmsTransactionManager"
		p:connectionFactory-ref="jmsFactory" />

	<bean id="jmsConnectionFactory"
		class="org.springframework.jms.connection.SingleConnectionFactory"
		p:targetConnectionFactory-ref="jmsFactory" />

	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"
		p:connectionFactory-ref="jmsConnectionFactory"
		p:defaultDestination-ref="destination" />

	<bean id="simpleJMSReceiver"
		class="de.jeha.spring_activemq_webapp.struts2.mdp.SimpleJMSReceiver" />

	<bean id="jmsMessageListener"
		class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
		<constructor-arg ref="simpleJMSReceiver" />
		<property name="messageConverter">
			<null />
		</property>
	</bean>

	<jms:listener-container container-type="default"
		connection-factory="jmsFactory" acknowledge="auto">
		<jms:listener destination="amq.test" ref="jmsMessageListener" />
	</jms:listener-container>

</beans>

I start the master and the slave with different ports via
$de.jeha.amq.host.port. For testing, these are the ports listed in the
failover url: failover:(tcp://10.121.123.26:61616,tcp://10.121.123.26:62616)

Question: Are there any issues with my app-context?

Thanks in advance

Albrecht
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-configure-Failover-in-Cluster-maybe-Master-Slave-tp3173307p3173307.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How to configure Failover in Cluster (maybe Master/Slave?)

Posted by joe_fernandez <jo...@ttmsolutions.com>.
I think your best bet is to implement a shared file system or DB master
slave. 

http://activemq.apache.org/shared-file-system-master-slave.html

If you want to be real adventurous, check out QSandra; A Cassandra backed
PersistenceAdapter for ActiveMQ. 

https://github.com/ticktock/qsandra#readme



-----
Joe
http://www.ttmsolutions.com/
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-configure-Failover-in-Cluster-maybe-Master-Slave-tp3173307p3173801.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.