ActiveMQ notes (4): Build a Broker cluster and activemqbroker

Source: Internet
Author: User

ActiveMQ notes (4): Build a Broker cluster and activemqbroker

The previous article introduced the two-node HA solution based on Networks of Borkers. This article continues to work with Networks of Brokers. When the scale of applications grows, 2-node brokers may still be unable to withstand access pressure. At this time, more brokers are required to create a larger broker cluster, but how can we reasonably set the network bridging between brokers, but there are some exquisite, first look at a bad design:

 

This architecture seems flawless, no problem. The three brokers communicate with each other, and the overall availability is extremely high. However, from the perspective of message routing, it is not a good design, when the producer sends a message to broker1, the Consumer may obtain the following two message paths:

A) producer-> broker1-> broker2

B) producer-> broker1-> broker3-> broker2

When there are more brokers, the situation will be more complex, as shown in the figure below:

The message routing path will be more:

A) producer-> broker1-> broker4

B) producer-> broker1-> broker2-> broker4

C) producer-> broker1-> broker2-> broker3-> broker4

D) producer-> broker1-> broker3-> broker4

It is hard to imagine that every time one node passes through, the message processing latency will increase. The more brokers, the more complicated the situation will be. In the end, the system will show that message processing is sometimes fast and sometimes slow, the overall performance is very unstable, so in actual production, do not use the scheme of interconnection between all brokers.

A reasonable solution is as follows:

This figure is inspired by the creation of a star network in the LAN. A Borker is placed in the center to act as the Hub and interconnect with all other brokers. No matter which Broker the Consumer connects, the message routing routes are relatively stable (up to three brokers). Although the Architecture performance is stable, the Hub in the center becomes a single point of failure. If the middle DockerHub fails, the whole system is also useless.

The improved architecture is as follows:

Essentially, it is still a star network, except that the hub is converted into two mutual backups, and each hub is connected to other peripheral brokers. The consumer connects to broker1/broker2/broker3 and the Producer (Producer) connect to hub1/hub2, and the maximum message path cannot exceed 3 brokers (Note: The producer can also connect to broker1/2/3, which is the same as that of the consumer, but the maximum message path will change to 4)

If you want to expand in the future, such as adding Broker4 and broker5..., you can directly modify the configuration on hub1/2 and add a connection with the new broker without affecting the message routing path length.

Finally, perform a drill on the local machine to provide some configuration examples:

1. Port Planning

activemq1: 61616 (broker1)activemq2: 61626 (broker2)activemq3: 61636 (broker3)activemq4: 61646 (broker-hub1)activemq5: 61656 (broker-hub2)

Five activemq instances in total, port 61616, 61626, 61636 for broker1, broker2, broker3, 61645, 61656 for broker-hub1, broker-hub2

2. activemq. xml configuration

Taking boker1 as an example, the configuration file content is as follows:

1 <beans 2 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 <bean class = "org. springframework. beans. factory. conf Ig. propertyPlaceholderConfigurer "> 8 <property name =" locations "> 9 <value> file :$ {activemq. conf}/credentials. properties </value> 10 </property> 11 </bean> 12 13 <broker xmlns = "http://activemq.apache.org/schema/core" brokerName = "broker1"> 14 <persistenceAdapter> 15 <kahaDB directory =" $ {activemq. data}/kahadb "/> 16 </persistenceAdapter> 17 <transportConnectors> 18 <transportctor name =" openwire "19 uri =" tc P: // 0.0.0.0: 61616? MaximumConnections = 1000 & amp; wireFormat. maxFrameSize = 104857600 "/> 20 </transportors ors> 21 </broker> 22 23 <import resource =" jetty. xml "/> 24 </beans>View Code

For details about broker2 and broker3, refer to this configuration to modify the port number and brokerName.

Broker-hub1 Configuration:

1 <beans 2 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 <bean class = "org. springframework. beans. factory. conf Ig. propertyPlaceholderConfigurer "> 8 <property name =" locations "> 9 <value> file :$ {activemq. conf}/credentials. properties </value> 10 </property> 11 </bean> 12 13 <broker xmlns = "http://activemq.apache.org/schema/core" brokerName = "broker-hub1"> 14 <networkConnectors> 15 <networkConnector uri =" static :( tcp: // 127.0.0.1: 61656, tcp: // 127.0.0.1: 61616, tcp: // 127.0.0.1: 61626, tcp: // 127.0.0.1: 61636) "duplex =" true "/> 16 </NetworkConnectors> 17 <persistenceAdapter> 18 <kahaDB directory = "$ {activemq. data}/kahadb "/> 19 </persistenceAdapter> 20 <transportors ors> 21 <transportconnename =" openwire "22 uri =" tcp: // 0.0.0.0: 61646? MaximumConnections = 1000 & amp; wireFormat. maxFrameSize = 104857600 "/> 23 </transportors ors> 24 </broker> 25 26 <import resource =" jetty. xml "/> 27 </beans>View Code

Broker-hub2 Configuration:

1 <beans 2 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 <bean class = "org. springframework. beans. factory. conf Ig. propertyPlaceholderConfigurer "> 8 <property name =" locations "> 9 <value> file :$ {activemq. conf}/credentials. properties </value> 10 </property> 11 </bean> 12 13 <broker xmlns = "http://activemq.apache.org/schema/core" brokerName = "broker-hub2"> 14 <networkConnectors> 15 <networkConnector uri =" static :( tcp: // 127.0.0.1: 61616, tcp: // 127.0.0.1: 61626, tcp: // 127.0.0.1: 61636) "duplex =" true "/> 16 </networkConnectors> 1 7 <persistenceAdapter> 18 <kahaDB directory = "$ {activemq. data}/kahadb "/> 19 </persistenceAdapter> 20 <transportors ors> 21 <transportconnename =" openwire "22 uri =" tcp: // 0.0.0.0: 61656? MaximumConnections = 1000 & amp; wireFormat. maxFrameSize = 104857600 "/> 23 </transportors ors> 24 </broker> 25 26 <import resource =" jetty. xml "/> 27 </beans>View Code

3. spring configuration file in java code

A) Producer

1 <bean id = "jmsFactory" class = "org. apache. activemq. pool. pooledConnectionFactory "destroy-method =" stop "> 2 <property name =" connectionFactory "> 3 <bean class =" org. apache. activemq. activeMQConnectionFactory "> 4 <! -- Broker address --> 5 <property name = "brokerURL" value = "failover :( tcp: // localhost: 61646, tcp: // localhost: 61656) "/> 6 <! -- The default value is 1000. If this value is not needed, you can reduce the value --> 7 <property name = "maxThreadPoolSize" value = "100"/> 8 <! -- <Property name = "userName" value = "system"/> --> 9 <! -- <Property name = "password" value = "manager"/> --> 10 </bean> 11 </property> 12 </bean>View Code

B) Consumer

1 <bean id = "jmsFactory" class = "org. apache. activemq. pool. pooledConnectionFactory "destroy-method =" stop "> 2 <property name =" connectionFactory "> 3 <bean class =" org. apache. activemq. activeMQConnectionFactory "> 4 <! -- Broker service address --> 5 <property name = "brokerURL" value = "failover :( tcp: // localhost: 61616, tcp: // localhost: 61626, tcp: // localhost: 61636) "/> 6 <! -- The default value is 1000. If this value is not needed, you can reduce the value --> 7 <property name = "maxThreadPoolSize" value = "100"/> 8 <! -- <Property name = "userName" value = "system"/> --> 9 <! -- <Property name = "password" value = "manager"/> --> 10 </bean> 11 </property> 12 </bean>View Code

 

References:

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

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

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.