centos activemq cluster configuration Networks of Brokers

Keywords: Apache JDK Java xml

1. Installing JDK Running Environment

 #cd /opt
 #wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz
 #tar zxvf jdk-8u112-linux-x64.tar.gz
 #Vi/etc/profile Add the following
 
export JAVA_HOME=/opt/jdk-8u112
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#source /etc/profile
#java -version
java version "1.8.0_12"
Java(TM) SE Runtime Environment (build 1.8.0_12-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.12-b03, mixed mode)

II. Installation and configuration of activemq

Here we configure Networks of Brokers cluster mode

The two broker s activemq-1 and activemq-2 are prepared for each other. The messages sent to you will be synchronized with me, and the messages sent to me will also be synchronized with you, thus realizing HA. The schematic diagram is as follows: 192.168.1.104:616161616< - > 192.168.1.105:61626.

The advantage of this HA scheme is that it occupies fewer nodes (only two nodes), and two broker s can respond to the receiving and sending of messages. The performance of this HA scheme is better than that of zookeeper scheme.



#wget 
#tar -zxvf apache-activemq-5.14.5-bin.tar.gz
# Configuration on VI conf/activemq.xml 192.168.1.104 (written 192.168.1.105:61626)

<beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
      <value>file:${activemq.conf}/credentials.properties</value>
    </property>
  </bean>

  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq-1">
    <networkConnectors>
      <networkConnector uri="static:(tcp://192.168.1.105:61626)"/>
    </networkConnectors>
    <persistenceAdapter>
      <kahaDB directory="${activemq.data}/kahadb"/>
    </persistenceAdapter>
    <transportConnectors>
      <transportConnector name="openwire"
                          uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    </transportConnectors>
  </broker>

  <import resource="jetty.xml"/>
</beans>

Similarly, in 192.168.1.105 Upper configuration (written to 192).168.1.104:61616)

#vi conf/activemq.xml
<beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
      <value>file:${activemq.conf}/credentials.properties</value>
    </property>
  </bean>

  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq-1">
    <networkConnectors>
      <networkConnector uri="static:(tcp://192.168.1.104:61616)"/>
    </networkConnectors>
    <persistenceAdapter>
      <kahaDB directory="${activemq.data}/kahadb"/>
    </persistenceAdapter>
    <transportConnectors>
      <transportConnector name="openwire"
                          uri="tcp://0.0.0.0:61626?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    </transportConnectors>
  </broker>

  <import resource="jetty.xml"/>
</beans>

After configuring, we start up separately.

# bin/activemq start
#Tail-f data/activemq.log View the log. You can see that the connection has been established

2017-05-12 09:33:43,404 | INFO  | Establishing network connection from vm://activemq-1?async=false&create=false to tcp://192.168.1.105:61626 | 
org.apache.activemq.network.DiscoveryNetworkConnector | main


Access the activemq console

http://ip:8161/admin/ (default account: admin; default password: admin)


When Producer and Constumer are connected to activemq, the configuration file can be written as follows:

<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
    <property name="connectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <!--broker Address of service-->
            <property name="brokerURL" value="failover:(tcp://192.168.1.104:61616,tcp://192.168.1.105:61626)"/>
            ...
        </bean>
    </property>
</bean>

The advantage of this HA scheme is that it occupies fewer nodes (only two nodes), and two broker s can respond to the receiving and sending of messages. The performance of this HA scheme is better than that of zookeeper scheme.






Posted by Jurik on Wed, 13 Feb 2019 06:09:20 -0800