ACTIVEMQ Note (3): HA scheme based on networks of brokers

Source: Internet
Author: User

The previous article introduced the Activemq HA scheme based on ZK, although it is easier to understand, but there are two deficiencies:

1) A large number of nodes occupied, 1 ZK cluster at least 3 nodes, 1 ACTIVEMQ cluster also have at least 3 nodes, but in fact, only one master node in the normal operation of external response, in other words, the cost of 6 nodes only to ensure 1 activemq The high availability of the master node is a waste of resources.

2) Performance degradation is too obvious, compared to the single-node activemq, performance decreased by nearly 1 orders of magnitude.

This article will introduce the HA scheme based on the networks of brokers, do not need to use the ZK and other 3rd party components, only need 2 ACTIVEMQ nodes can achieve similar effect, before entering the topic, first to briefly talk about the concept of broker.

The term broker is intended to be a " broker, Middleman ", used in the framework of ACTIVEMQ, i.e. broker as an intermediary (or agent) between producer and consumer, and producers need not know where the consumer is, how to consume the details, As long as the message is thrown to the middleman broker, similarly, the consumer does not have to care about which producer the message came from, it only knows that it was taken from the broker, and if you draw a picture to describe it, this is the following (referring to the image from the last reference article in this article)

So what happens when a producer sends a message to the broker? This process is described:

1) producers send messages to broker

2) Broker stores messages on the ground

3) Then give feedback to the producers: things I have done!

Go ahead and see how consumers are dealing with broker:

1) The broker will receive the message, out of the DB

2) then send to the consumer

3) If the consumer is using auto-confirm mode (ie: Session.auto_acknowledge), then consumer will tell Broker:ok immediately, the message I have received.

4) Then do your own business processing

5) Once the broker receives confirmation, it will immediately update the status of the message as consumed (or directly deleted, depending on the implementation mechanism of persistence) (Note: Although step 5 in the figure is ranked after step 4, steps 4 and 5 occur almost simultaneously)

In some large applications, if a broker has a performance bottleneck that cannot withstand stress, it may split into multiple brokers, as shown in:

(Note: The middle Arrow method is not the data flow, but should be understood as a call relationship, that is: Producer call Broker1,consumer call Broker2 ...)

Producer sends the message to Broker1, and consumer receives the message from another Broker2, a bit like the meaning of the database read and write separation, so that the performance of the system can improve a certain degree of improvement, but the problem comes, Broker1 on the message, How to sync to Broker2, which relies on the Networkconnector configuration.

1 <Beans2         xmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 5 http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd ">6 7   <Beanclass= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">8     < Propertyname= "Locations">9       <value>File:${activemq.conf}/credentials.properties</value>Ten     </ Property> One   </Bean> A  -   <Brokerxmlns= "Http://activemq.apache.org/schema/core"Brokername= "Activemq-1"> -     <networkconnectors> the       <NetworkconnectorURI= "Static: (tcp://127.0.0.1:61626)"/> -     </networkconnectors> -     <Persistenceadapter> -       <kahadbDirectory= "${ACTIVEMQ.DATA}/KAHADB"/> +     </Persistenceadapter> -     <transportconnectors> +       <Transportconnectorname= "Openwire" A URI= "tcp://0.0.0.0:61616?maximumconnections=1000&amp;wireformat.maxframesize=104857600"/> at     </transportconnectors> -   </Broker> -  -   <ImportResource= "Jetty.xml"/> - </Beans>
View Code

Note: 14-16 lines and 21-22 lines, the broker exposed 61616 port, while "connected" to 61626 port (that is, another 1 broker), the final effect is equivalent, if there is producer send the message to 616 16 (broker1), this message can also be consumed from another broker (61626 port).

Understanding these fundamentals, on the 61626 corresponding to the ACTIVEMQ, also do a similar configuration, but the "connection direction" is just the opposite, refer to the following configuration:

1 <Beans2         xmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 5 http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd ">6 7     <Beanclass= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">8         < Propertyname= "Locations">9             <value>File:${activemq.conf}/credentials.properties</value>Ten         </ Property> One     </Bean> A  -     <Brokerxmlns= "Http://activemq.apache.org/schema/core"Brokername= "Activemq-2"> -         <networkconnectors> the             <NetworkconnectorURI= "Static: (tcp://127.0.0.1:61616)"/> -         </networkconnectors> -         <Persistenceadapter> -             <kahadbDirectory= "${ACTIVEMQ.DATA}/KAHADB"/> +         </Persistenceadapter> -         <transportconnectors> +             <Transportconnectorname= "Openwire" A URI= "tcp://0.0.0.0:61626?maximumconnections=1000&amp;wireformat.maxframesize=104857600"/> at         </transportconnectors> -     </Broker> -  -     <ImportResource= "Jetty.xml"/> - </Beans>
View Code

(Note: If you want to access the admin interface on all 2 ACTIVEMQ, the ports in the Jetty.xml should be modified, do not conflict)

In this way, activemq-1 and activemq-2 These two brokers are prepared for each other, the message sent to you will be synced to me, the message sent to me will be synchronized to you, the implementation of HA, as follows:

When producer and consumer are connected to ACTIVEMQ, the configuration file can be written like this:

1 <BeanID= "Jmsfactory"class= "Org.apache.activemq.pool.PooledConnectionFactory"Destroy-method= "Stop">2     < Propertyname= "ConnectionFactory">3         <Beanclass= "Org.apache.activemq.ActiveMQConnectionFactory">4             <!--Address of broker service -5             < Propertyname= "Brokerurl"value= "Failover: (tcp://localhost:61616,tcp://localhost:61626)"/>6             ...7         </Bean>8     </ Property>9 </Bean>

The advantage of this HA scheme is that it takes up fewer nodes (only 2 nodes), and 2 brokers can respond to the receipt and delivery of messages, which is better than the zookeeper scheme.

Reference article:

Http://www.jakubkorab.net/2011/11/understanding-activemq-broker-networks.html

Http://activemq.apache.org/networks-of-brokers.html

ACTIVEMQ Note (3): HA scheme based on networks of brokers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.