activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Bain <tb...@alumni.duke.edu>
Subject Re: Consumers connected to several brokers
Date Mon, 11 Sep 2017 23:29:57 GMT
Do you need to have access to messages published to the first broker when
it goes down? If so, you should be looking at a master/slave pair instead
of two active brokers.

If not, you should network the two brokers to allow messages published on
either one to be delivered to a consumer on any broker. Just be sure to pay
attention to the Stuck Messages section of the Network of Brokers page at
http://activemq.apache.org/networks-of-brokers.html

Tim

On Sep 11, 2017 7:02 AM, "stonebreaker" <william.gotti@gmail.com> wrote:

> Hi all,
>
> I have some concerns about the configuration of my spring application.
> I have 2 brokers (one main and one failover) and I want my client to
> produce
> messages to the first broker. It should go to the second one just in case
> the first broker is down, and automatically go back to the first broker
> when
> it's up again.
> My client also consumes these messages and I'd like *the consumers to be
> constantly connected to both brokers* so that I can ensure no message is
> left on a broker.
>
> *ActiveMQ 5.14.1* is used for the brokers
> My client is a Java web application using *spring 4.0.1.RELEASE,
> activemq-all 5.11.0* and running on tomcat 7. It must be able to process
> several messages (~10) by second.
>
> For my producers, I use this JNDI resource to build the connection factory:
> <Resource auth="Container" brokerName="broker"
> brokerURL="failover:(tcp://broker1,tcp://broker2)?
> randomize=false&amp;timeout=1000"
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" initialSize="10"
> name="activemq.connectionFactory"
> type="org.apache.activemq.ActiveMQConnectionFactory"/>
>
> And here are the Spring beans:
> <bean id="jmsFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory"
> destroy-method="stop" >
>         <property name="connectionFactory" ref="jmsConnectionFactory"/>
>         <property name="useAnonymousProducers" value="false"/>
>         <property name="blockIfSessionPoolIsFullTimeout"
> value="5000"></property>
>         <property name="idleTimeout" value="300000"></property>
> </bean>
>
> <bean id="myProducer" class="org.springframework.jms.core.JmsTemplate">
>         <property name="connectionFactory" ref="jmsFactory" />
>         <property name="defaultDestination" ref="myQueue" />
>         <property name="sessionTransacted" value="false" />
>         <property name="deliveryMode" value="1"/>
>         <property name="explicitQosEnabled" value="true"/>
> </bean>
>
> For the consumers, I can't find the appropriate way to connect to both
> brokers so I duplicated my configuration like below but it doesn't look
> right:
> I have 2 JNDI resources:
> <Resource auth="Container" brokerName="broker1" brokerURL="tcp://broker1"
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" initialSize="10"
> name="activemq.consumer.main.connectionFactory"
> type="org.apache.activemq.ActiveMQConnectionFactory"/>
> <Resource auth="Container" brokerName="broker2" brokerURL="tcp://broker2"
> factory="org.apache.activemq.jndi.JNDIReferenceFactory" initialSize="10"
> name="activemq.consumer.failover.connectionFactory"
> type="org.apache.activemq.ActiveMQConnectionFactory"/>
>
> And here are the spring beans:
> <jee:jndi-lookup resource-ref="true" id="jmsMainConsumerConnectionFactory"
> jndi-name="activemq.consumer.main.connectionFactory"
> proxy-interface="javax.jms.ConnectionFactory" lookup-on-startup="true"/>
> <jee:jndi-lookup resource-ref="true"
> id="jmsFailoverConsumerConnectionFactory"
> jndi-name="activemq.consumer.failover.connectionFactory"
> proxy-interface="javax.jms.ConnectionFactory" lookup-on-startup="true"/>
>
> <bean id="jmsMainConsumerFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory"
> destroy-method="stop" >
>         <property name="connectionFactory" ref="
> jmsMainConsumerConnectionFactory"
> />
>         <property name="maxConnections" value="2" />
>         <property name="idleTimeout" value="300000" />
> </bean>
> <bean id="jmsFailoverConsumerFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory"
> destroy-method="stop" >
>         <property name="connectionFactory"
> ref="jmsFailoverConsumerConnectionFactory"/>
>         <property name="maxConnections" value="2" />
>         <property name="idleTimeout" value="300000" />
> </bean>
>
> <bean id="jmsMainListenerContainer"
> class="org.springframework.jms.listener.DefaultMessageListenerContainer"
> destroy-method="shutdown">
>         <property name="connectionFactory" ref="jmsMainConsumerFactory" />
>         <property name="messageListener" ref="myMessageListener"/>
>         <property name="destination" ref="myQueue" />
>         <property name="maxConcurrentConsumers" value="30" />
>         <property name="concurrentConsumers" value="20"/>
>         <property name="sessionTransacted" value="false" />
>         <property name="exposeListenerSession" value="true" />
>         <property name="cacheLevelName" value="CACHE_CONSUMER" />
> </bean>
> <bean id="jmsFailoverListenerContainer"
> class="org.springframework.jms.listener.DefaultMessageListenerContainer"
> destroy-method="shutdown">
>         <property name="connectionFactory" ref="jmsFailoverConsumerFactory"
> />
>         <property name="messageListener" ref="myMessageListener"/>
>         <property name="destination" ref="myQueue" />
>         <property name="maxConcurrentConsumers" value="30" />
>         <property name="concurrentConsumers" value="20"/>
>         <property name="sessionTransacted" value="false" />
>         <property name="exposeListenerSession" value="true" />
>         <property name="cacheLevelName" value="CACHE_CONSUMER" />
> </bean>
>
> It doesn't make sense to duplicate these above consumers configurations so
> could you please help me find the right way to implement my use case?
> Also, if you have any other recommendation, I'd really appreciate.
>
> Thanks.
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message