溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ActiveMQ之brokers network集群

發(fā)布時間:2020-06-08 06:17:24 來源:網(wǎng)絡(luò) 閱讀:1837 作者:乾坤刀 欄目:軟件技術(shù)

一、集群配置方式類型

master-slave
<networkConnectors>
  <networkConnector uri="masterslave:(tcp://host1:61616,tcp://host2:61616,tcp://..)"/>
</networkConnectors>
  • uri列表中對應(yīng)的順序就是MASTER,SLAVE1,SLAVE2...SLAVE;
  • master-slave的作用就是brokers之間的主從,同一時刻只能連接一個broker。通常先連接master,如果master連接不上,則連接slave;
  • brokers之間的消息同步機(jī)制是通過<persistenceAdapter>共享的存儲方式來共享數(shù)據(jù)的,如:jdbc/kahaDB/replicaLevelDB(zookeeper)。同時,brokers之間也是通過獲取數(shù)據(jù)存儲的訪問權(quán)來獲取broker的主導(dǎo)權(quán)(即哪個broker激活)。
  • zookeeper做masterslave時,brokers的名字必須一致,否則zookeeper會認(rèn)為不符合2n+1的規(guī)則。
  • masterslave這種配置既可以在activeMQ.xml中配置,也可以在client端使用。通常建議在client使用。雖然master-slave可以提高可用性,但是負(fù)載均衡的功能減弱,并且很多時候會浪費slave broker服務(wù)器。
broker static discover
<networkConnectors>
  <networkConnector uri="static:(tcp://host1:61616,tcp://host2:61617,tcp://..)"/>
</networkConnectors>

表示當(dāng)前l(fā)ocal broker與remote broker(61616/61617)建立的單向網(wǎng)絡(luò)連接。即local broker可以將消息傳遞給remote broker,但反過來就不行。duplex="true" 屬性配置可以開啟雙向通信。

broker multicast discover
<networkConnectors>
   <networkConnector uri="multicast://default"/>
</networkConnectors>

<transportConnector uri="tcp://localhost:0" discoveryUri="multicast://default"/>

組播發(fā)現(xiàn)會自動發(fā)現(xiàn)同網(wǎng)絡(luò)中的broker并進(jìn)行連接通信。注意:必須是同網(wǎng)絡(luò)中。
在實際的配置很少這樣配置,因為無法保證哪些brokers建立了連接。對于master-slave配置也不是很好。

dynamicallyIncludedDestinations
<dynamicallyIncludedDestinations>
     <queue physicalName="include.test.foo"/>
     <topic physicalName="include.test.bar"/>
</dynamicallyIncludedDestinations>

當(dāng)networkConnector中連接的broker有customers時,那么對應(yīng)的destinations才會傳遞到對應(yīng)的broker。否則,不傳遞。這中方式對于point-to-point的方式就比較合適。

staticallyIncludedDestinations
<staticallyIncludedDestinations>
     <queue physicalName="always.include.queue"/>
     <topic physicalName="always.include.topic"/>
</staticallyIncludedDestinations>

不管networkConnector中連接的broker有無customers,都會講消息發(fā)送到每個broker去。這種方式比較適合topic的消息方式。

excludedDestinations
<excludedDestinations>
     <queue physicalName="exclude.test.foo"/>
     <topic physicalName="exclude.test.bar"/>
</excludedDestinations>

networkConnector中指定某些detination不會發(fā)送到remote brokers.

networkConnector中uri的參數(shù)
uri="static:(tcp://host1:61616,tcp://host2:61616)?maxReconnectDelay=5000&useExponentialBackOff=false"

initialReconnectDelay:重連的時間間隔。
maxReconnectDelay:最大重連時間。即initialReconnectDelay次數(shù)
useExponentialBackOff:一次連接失敗,后面的重連時間是否依次遞增。
backOffMultiplier:當(dāng)useExponentialBackOff=true,重連時間的間隔的倍數(shù),即initialReconnectDelay
backOffMultiplier

networkConnector屬性配置

name:連接名稱,多個時必須唯一。
dynamicOnly:
decreaseNetworkConsumerPriority:
networkTTL:
messageTTL:
consumerTTL:
conduitSubscriptions:管道訂閱。即一個broker有多個customers,也只會認(rèn)為是一個customer.
excludedDestinations:
dynamicallyIncludedDestinations:
useVirtualDestSubs:
staticallyIncludedDestinations:
duplex:是否開啟雙工通信
prefetchSize:
suppressDuplicateQueueSubscriptions:
bridgeTempDestinations:
alwaysSyncSend:
staticBridge:靜態(tài)連接橋。與staticallyIncludedDestinations聯(lián)合使用
userName:networkConnector連接用戶名
password:networkConnector連接密碼

二、集群實例

ActiveMQ之brokers network集群

broker-master

<networkConnectors>
    <networkConnector name="connector_master_slave" uri="static:(tcp://localhost:61618,tcp://localhost:61619)" 
                           userName="admin" password="admin123"/>
   <networkConnector name="connector_brokers" uri="static:(tcp://localhost:61620,tcp://localhost:61621)"                         userName="admin" password="admin123">
     <dynamicallyIncludedDestinations>
          <queue physicalName=">"/>
     </dynamicallyIncludedDestinations>
     <staticallyIncludedDestinations>
           <topic physicalName=">"/>
     </staticallyIncludedDestinations>
   </networkConnector>
</networkConnectors>

<transportConnector name="openwire" uri="tcp://0.0.0.0:61617?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>

broker-slave01

<networkConnectors>
    <networkConnector name="connector_master_slave" uri="static:(tcp://localhost:61617,tcp://localhost:61619)"              userName="admin" password="admin123"/>
    <networkConnector name="connector_brokers" uri="static:(tcp://localhost:61620,tcp://localhost:61621)"                            userName="admin" password="admin123">
       <dynamicallyIncludedDestinations>
             <queue physicalName=">"/>
       </dynamicallyIncludedDestinations>
       <staticallyIncludedDestinations>
             <topic physicalName=">"/>
       </staticallyIncludedDestinations>
    </networkConnector>
</networkConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>

broker-slave02

<networkConnectors>
   <networkConnector name="connector_master_slave" 
                           uri="static:(tcp://localhost:61617,tcp://localhost:61618)" userName="admin" password="admin123"/>
   <networkConnector name="connector_brokers" uri="static:(tcp://localhost:61620,tcp://localhost:61621)"                          userName="admin" password="admin123">
          <dynamicallyIncludedDestinations>
                   <queue physicalName=">"/>
          </dynamicallyIncludedDestinations>
          <staticallyIncludedDestinations>
                   <topic physicalName=">"/>
          </staticallyIncludedDestinations>
     </networkConnector>
</networkConnectors>

broker-cluster01

<networkConnectors>
     <networkConnector uri="static:(tcp://localhost:61621)" duplex="false" name="connector_broker_normal"                            userName="admin" password="admin123">
         <dynamicallyIncludedDestinations>
                   <queue physicalName=">" />
                   <topic physicalName=">" />
         </dynamicallyIncludedDestinations>
     </networkConnector>
</networkConnectors>

<transportConnector name="openwire" uri="tcp://0.0.0.0:61620?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>

broker-cluster02

<networkConnectors>
     <networkConnector uri="static:(tcp://localhost:61620)" duplex="false" name="connector_broker_normal"                           userName="admin" password="admin123">
         <dynamicallyIncludedDestinations>
                 <queue physicalName=">" />
                 <topic physicalName=">" />
         </dynamicallyIncludedDestinations>
     </networkConnector>
</networkConnectors>

<transportConnector name="openwire"uri="tcp://0.0.0.0:61621?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>

brokers的安全配置

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

<plugins> 
   <simpleAuthenticationPlugin> 
       <users> 
         <authenticationUser username="${activemq.username}" password="${activemq.password}"  groups="admins"/>
        </users> 
   </simpleAuthenticationPlugin> 

        <authorizationPlugin> 
          <map> 
           <authorizationMap> 
            <authorizationEntries>
             <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
             <authorizationEntry topic=">" read="admins" write="admins" admin="admins"/>
            </authorizationEntries>
            <tempDestinationAuthorizationEntry>
             <tempDestinationAuthorizationEntry read="admins" write="admins" admin="admins"/>
            </tempDestinationAuthorizationEntry>
           </authorizationMap> 
          </map> 
   </authorizationPlugin>
</plugins>

參考文檔:
http://activemq.apache.org/networks-of-brokers.html
http://shift-alt-ctrl.iteye.com/blog/2070531
https://www.cnblogs.com/shihaiming/p/6018916.html

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI