日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用ActiveMQ –具有故障转移协议的“主/从”配置

發布時間:2023/12/3 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用ActiveMQ –具有故障转移协议的“主/从”配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

介紹

ActiveMQ代理往往是企業中消息傳遞基礎結構的核心部分。 此消息傳遞基礎結構的高度可用性和可伸縮性至關重要。 請閱讀此鏈接 ,以了解有關創建經紀人網絡以支持各種用例的更多信息。 ActiveMQ的流行用例之一是帶有共享數據庫的主/從配置。 使用此配置時,消息使用者和生產者可以使用不帶有中斷轉移協議的ActiveMQ的連接工廠來不受干擾地進行操作。 當從屬ActiveMQ節點接管成為主節點時,故障轉移協議使使用者和生產者不必處理任何潛在的停機時間或應用程序級別的重新連接邏輯,如果當前主節點由于任何原因而發生故障,該故障轉移協議就會發生。 我必須警告,不得使用此配置來掩蓋掉主節點的任何問題。 我們應該消除導致計劃外主節點中斷的任何原因。

總覽

在此博客中,我將演示以下內容:

  • 在具有共享的基于KahaDB文件的數據庫的主/從配置中運行2個ActiveMQ節點。
  • 將托管在Tomcat實例中的ActiveMQ Web控制臺配置為指向群集中的哪個節點為主節點。
  • 故障轉移方案。
  • 故障轉移忽略的消息發布者和使用者行為。
  • 先決條件

  • 安裝ActiveMQ版本5.8.0
  • 從此處下載ActiveMQ版本5.8.0 Web控制臺之戰
  • 安裝Tomcat版本7.0.35 –承載ActiveMQ Web控制臺應用程序
  • 深潛

    我們將在同一臺Windows 7計算機上創建一個2節點ActiveMQ群集。 我們將需要配置端口(TCP和JMX),以便沒有沖突。 ActiveMQ提供了一個名為“ activemq-admin.bat”的腳本,該腳本可幫助使用相同的二進制文件(類似于Tomcat)運行ActiveMQ的多個實例。 讓我們繼續創建broker-1和broker-2實例。

    命令: activemq-admin創建<DIR-for-ActiveMQ-node>

    C:\apache-activemq-5.8.0\bin>activemq-admin create ..\cluster\broker-1Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jreHeap sizes: current=125632k ?free=124976k ?max=1864192kJVM args: -Dactivemq.classpath=C:\apache-activemq-5.8.0\bin\..\conf;C:\apache-activemq-5.8.0\bin\..\data; -Dactivemq.home=C:\apache-activemq-5.8.0 \bin\.. -Dactivemq.base=C:\apache-activemq-5.8.0\bin\.. -Dactivemq.data=C:\apache-activemq-5.8.0\bin\..\data -Djava.io.tmpdir=C:\apache-activemq-5.8.0 \bin\..\data\tmp -Dactivemq.conf=C:\apache-activemq-5.8.0\bin\..\conf Extensions classpath:[C:\apache-activemq-5.8.0\bin\..\lib,C:\apache-activemq-5.8.0\bin\..\lib\camel,C:\apache-activemq-5.8.0\bin\..\lib\optional,C:\apache-activemq-5.8.0 \bin\..\lib\web,C:\apache-activemq-5.8.0\bin\..\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\bin\..\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\bin\..\data Running create broker task... Creating directory: C:\apache-activemq-5.8.0\cluster\broker-1 Creating directory: C:\apache-activemq-5.8.0\cluster\broker-1\bin Creating directory: C:\apache-activemq-5.8.0\cluster\broker-1\conf Creating new file: C:\apache-activemq-5.8.0\cluster\broker-1\bin\broker-1.bat Creating new file: C:\apache-activemq-5.8.0\cluster\broker-1\bin\broker-1 Copying from: C:\apache-activemq-5.8.0\conf\activemq.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-command.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-command.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-demo.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker1.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-dynamic-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker2.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-dynamic-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-jdbc.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-jdbc.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-scalability.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-scalability.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-security.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-security.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-specjms.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-specjms.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker1.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-static-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker2.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-static-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-stomp.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-stomp.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-throughput.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-throughput.xml Copying from: C:\apache-activemq-5.8.0\conf\broker-localhost.certto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker-localhost.cert Copying from: C:\apache-activemq-5.8.0\conf\broker.ksto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker.ks Copying from: C:\apache-activemq-5.8.0\conf\broker.tsto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker.ts Copying from: C:\apache-activemq-5.8.0\conf\camel.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\camel.xml Copying from: C:\apache-activemq-5.8.0\conf\client.ksto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\client.ks Copying from: C:\apache-activemq-5.8.0\conf\client.tsto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\client.ts Copying from: C:\apache-activemq-5.8.0\conf\credentials-enc.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\credentials-enc.properties Copying from: C:\apache-activemq-5.8.0\conf\credentials.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\credentials.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty-demo.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\jetty-realm.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty-realm.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty.xmlto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty.xml Copying from: C:\apache-activemq-5.8.0\conf\jmx.accessto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jmx.access Copying from: C:\apache-activemq-5.8.0\conf\jmx.passwordto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jmx.password Copying from: C:\apache-activemq-5.8.0\conf\log4j.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\log4j.properties Copying from: C:\apache-activemq-5.8.0\conf\logging.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-1\conf\logging.properties

    現在讓我們創建broker-2實例…

    C:\apache-activemq-5.8.0\bin>activemq-admin create ..\cluster\broker-2Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jreHeap sizes: current=125632k ?free=124976k ?max=1864192kJVM args: -Dactivemq.classpath=C:\apache-activemq-5.8.0\bin\..\conf;C:\apache-activemq-5.8.0\bin\..\data; -Dactivemq.home=C:\apache-activemq-5.8.0 \bin\.. -Dactivemq.base=C:\apache-activemq-5.8.0\bin\.. -Dactivemq.data=C:\apache-activemq-5.8.0\bin\..\data -Djava.io.tmpdir=C:\apache-activemq-5.8.0 \bin\..\data\tmp -Dactivemq.conf=C:\apache-activemq-5.8.0\bin\..\conf Extensions classpath:[C:\apache-activemq-5.8.0\bin\..\lib,C:\apache-activemq-5.8.0\bin\..\lib\camel,C:\apache-activemq-5.8.0\bin\..\lib\optional,C:\apache-activemq-5.8.0 \bin\..\lib\web,C:\apache-activemq-5.8.0\bin\..\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\bin\..\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\bin\..\data Running create broker task... Creating directory: C:\apache-activemq-5.8.0\cluster\broker-2 Creating directory: C:\apache-activemq-5.8.0\cluster\broker-2\bin Creating directory: C:\apache-activemq-5.8.0\cluster\broker-2\conf Creating new file: C:\apache-activemq-5.8.0\cluster\broker-2\bin\broker-2.bat Creating new file: C:\apache-activemq-5.8.0\cluster\broker-2\bin\broker-2 Copying from: C:\apache-activemq-5.8.0\conf\activemq.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-command.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-command.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-demo.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker1.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-dynamic-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-dynamic-network-broker2.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-dynamic-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-jdbc.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-jdbc.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-scalability.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-scalability.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-security.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-security.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-specjms.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-specjms.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker1.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-static-network-broker1.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-static-network-broker2.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-static-network-broker2.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-stomp.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-stomp.xml Copying from: C:\apache-activemq-5.8.0\conf\activemq-throughput.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-throughput.xml Copying from: C:\apache-activemq-5.8.0\conf\broker-localhost.certto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker-localhost.cert Copying from: C:\apache-activemq-5.8.0\conf\broker.ksto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker.ks Copying from: C:\apache-activemq-5.8.0\conf\broker.tsto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker.ts Copying from: C:\apache-activemq-5.8.0\conf\camel.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\camel.xml Copying from: C:\apache-activemq-5.8.0\conf\client.ksto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\client.ks Copying from: C:\apache-activemq-5.8.0\conf\client.tsto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\client.ts Copying from: C:\apache-activemq-5.8.0\conf\credentials-enc.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\credentials-enc.properties Copying from: C:\apache-activemq-5.8.0\conf\credentials.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\credentials.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty-demo.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty-demo.xml Copying from: C:\apache-activemq-5.8.0\conf\jetty-realm.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty-realm.properties Copying from: C:\apache-activemq-5.8.0\conf\jetty.xmlto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty.xml Copying from: C:\apache-activemq-5.8.0\conf\jmx.accessto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jmx.access Copying from: C:\apache-activemq-5.8.0\conf\jmx.passwordto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jmx.password Copying from: C:\apache-activemq-5.8.0\conf\log4j.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\log4j.properties Copying from: C:\apache-activemq-5.8.0\conf\logging.propertiesto: C:\apache-activemq-5.8.0\cluster\broker-2\conf\logging.properties

    您可能已經注意到上面的以下屬性:

    ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\bin\.. ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\bin\..\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\bin\..\data

    這些屬性需要固定,因為我們希望ACTIVE-1和Broker-2的ACTIVEMQ_BASE和ACTIVEMQ_CONF有所不同。

    我們需要編輯以下文件:

    • C:\ apache-activemq-5.8.0 \ cluster \ broker-1 \ bin目錄中的broker-1.bat
      • 設置ACTIVEMQ_HOME =” C:/apache-activemq-5.8.0”
    • C:\ apache-activemq-5.8.0 \ cluster \ broker-2 \ bin目錄中的broker-2.bat
      • 設置ACTIVEMQ_HOME =” C:/apache-activemq-5.8.0”

    您可能會觀察到broker-1和broker-2節點共享相同的ACTIVEMQ_DATA文件夾。 由于我們使用內置的KahaDB來保持持久性,因此broker-1和broker-2都將共享這一點。

    我們需要區分Broker-1和Broker-2的tcp端口,還需要啟用JMX并配置JMX端口以進行遠程監視。

    讓我們編輯broker-1的activemq.xml來修復tcp端口:

    <transportConnectors><!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB --><transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600"/><!--<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireformat.maxFrameSize=104857600"/>--> </transportConnectors>

    讓我們編輯broker-1的activemq.xml以啟用JMX監視,注意下面的useJMX =“ true”屬性。

    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker-1" dataDirectory="${activemq.data}" useJmx="true">

    讓我們配置JMX端口

    <managementContext><managementContext createConnector="true" connectorPort="1099"/> </managementContext>

    對broker-2重復相同的步驟。 將TCP端口設置為61626,將JMX端口設置為2099。

    啟動broker-1。

    C:\apache-activemq-5.8.0\cluster\broker-1\bin>broker-1.bat Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jreHeap sizes: current=1004928k free=994439k max=1004928kJVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Dactivemq.classpath=C:/apache-activemq- 5.8.0/cluster/broker-1/conf;C:/apache-activemq-5.8.0/cluster/broker-1/conf;C:/apache-activemq-5.8.0/conf; -Dactivemq.home=C:/apache-activemq-5.8.0 -Da ctivemq.base=C:/apache-activemq-5.8.0/cluster/broker-1 -Dactivemq.conf=C:/apache-activemq-5.8.0/cluster/broker-1/conf -Dactivemq.data=C:/apache-active mq-5.8.0\data -Djava.io.tmpdir=C:/apache-activemq-5.8.0\data\tmp Extensions classpath:[C:\apache-activemq-5.8.0\cluster\broker-1\lib,C:\apache-activemq-5.8.0\lib,C:\apache-activemq-5.8.0\cluster\broker-1\lib\camel,C:\apache-activemq-5 .8.0\cluster\broker-1\lib\optional,C:\apache-activemq-5.8.0\cluster\broker-1\lib\web,C:\apache-activemq-5.8.0\cluster\broker-1\lib\extra,C:\apache-act ivemq-5.8.0\lib\camel,C:\apache-activemq-5.8.0\lib\optional,C:\apache-activemq-5.8.0\lib\web,C:\apache-activemq-5.8.0\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0 ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\cluster\broker-1 ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\cluster\broker-1\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\data Loading message broker from: xbean:activemq.xmlINFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@71060478: startup date [Tue Jul 09 16:59:15 CDT 2013]; root of context hierarchyINFO | PListStore:[C:\apache-activemq-5.8.0\data\broker-1\tmp_storage] startedINFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\apache-activemq-5.8.0\data\kahadb]INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmiINFO | KahaDB is version 4INFO | Recovering from the journal ...INFO | Recovery replayed 1 operations from the journal in 0.028 seconds.INFO | Apache ActiveMQ 5.8.0 (broker-1, ID:AKUNTAMU-1-27777-1373407157813-0:1) is startingINFO | Listening for connections at: tcp://AKUNTAMU-1:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600INFO | Connector openwire StartedINFO | Apache ActiveMQ 5.8.0 (broker-1, ID:AKUNTAMU-1-27777-1373407157813-0:1) startedINFO | For help or more information please see: http://activemq.apache.orgWARN | Store limit is 102400 mb, whilst the data directory: C:\apache-activemq-5.8.0\data\kahadb only has 38889 mb of usable space ERROR | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\apache-activemq-5.8.0\data\broker-1\tmp_storage only has 38889 mb o f usable spaceINFO | Web console type: embeddedINFO | ActiveMQ WebConsole initialized.INFO | Initializing Spring FrameworkServlet 'dispatcher'INFO | jolokia-agent: No access restrictor found at classpath:/jolokia-access.xml, access to all MBeans is allowed

    啟動broker-2。

    您將觀察到broker-2無法獲取該鎖,因為broker-1已經抓住了它。 broker-2將繼續嘗試每10秒獲取一次鎖定。

    C:\apache-activemq-5.8.0\cluster\broker-2\bin>broker-2.bat Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jreHeap sizes: current=1004928k free=994439k max=1004928kJVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Dactivemq.classpath=C:/apache-activemq- 5.8.0/cluster/broker-2/conf;C:/apache-activemq-5.8.0/cluster/broker-2/conf;C:/apache-activemq-5.8.0/conf; -Dactivemq.home=C:/apache-activemq-5.8.0 -Da ctivemq.base=C:/apache-activemq-5.8.0/cluster/broker-2 -Dactivemq.conf=C:/apache-activemq-5.8.0/cluster/broker-2/conf -Dactivemq.data=C:/apache-active mq-5.8.0\data -Djava.io.tmpdir=C:/apache-activemq-5.8.0\data\tmp Extensions classpath:[C:\apache-activemq-5.8.0\cluster\broker-2\lib,C:\apache-activemq-5.8.0\lib,C:\apache-activemq-5.8.0\cluster\broker-2\lib\camel,C:\apache-activemq-5 .8.0\cluster\broker-2\lib\optional,C:\apache-activemq-5.8.0\cluster\broker-2\lib\web,C:\apache-activemq-5.8.0\cluster\broker-2\lib\extra,C:\apache-act ivemq-5.8.0\lib\camel,C:\apache-activemq-5.8.0\lib\optional,C:\apache-activemq-5.8.0\lib\web,C:\apache-activemq-5.8.0\lib\extra] ACTIVEMQ_HOME: C:\apache-activemq-5.8.0 ACTIVEMQ_BASE: C:\apache-activemq-5.8.0\cluster\broker-2 ACTIVEMQ_CONF: C:\apache-activemq-5.8.0\cluster\broker-2\conf ACTIVEMQ_DATA: C:\apache-activemq-5.8.0\data Loading message broker from: xbean:activemq.xmlINFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@420f9c40: startup date [Tue Jul 09 17:02:55 CDT 2013]; root of context hierarchyINFO | PListStore:[C:\apache-activemq-5.8.0\data\broker-2\tmp_storage] startedINFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\apache-activemq-5.8.0\data\kahadb]INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked.INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:2099/jmxrmiINFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked.INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked.

    現在,讓我們配置ActiveMQ Web控制臺。

    默認情況下,ActiveMQ分發包含管理Web控制臺,但是在“主/從”配置中,未知哪個節點是主節點。 因此,使用嵌入式Web控制臺沒有任何意義。 因此,最好將ActiveMQ Web控制臺放在ActiveMQ節點之外。

    您可以通過在每個ActiveMQ節點的conf目錄中的activemq.xml中注釋以下行來禁用每個節點中的嵌入式ActiveMQ Web控制臺。

    <!--<import resource="jetty.xml"/>-->

    對于我們的示例,我們將在Tomcat容器中部署ActiveMQ Web控制臺Web應用程序,然后配置ActiveMQ Web控制臺應用程序以智能地指向ActiveMQ群集中的主節點。

    因此,讓我們將activemq-web-console-5.8.0.war復制到Tomcat的webapps目錄中。 將以下行添加到catalina.bat

    set JAVA_OPTS=-Dwebconsole.type=properties -Dwebconsole.jms.url=failover:(tcp://localhost:61616,tcp://localhost:61626) -Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi,service:jmx:rmi:///jndi/rmi://localhost:2099/jmxrmi

    現在讓我們啟動Tomcat。

    C:\apache-tomcat-7.0.35\bin>.\catalina.bat run Using CATALINA_BASE: "C:\apache-tomcat-7.0.35" Using CATALINA_HOME: "C:\apache-tomcat-7.0.35" Using CATALINA_TMPDIR: "C:\apache-tomcat-7.0.35\temp" Using JRE_HOME: "C:\Program Files\Java\jdk1.6.0_31" Using CLASSPATH: "C:\apache-tomcat-7.0.35\bin\bootstrap.jar;C:\apache-tomcat-7.0.35\bin\tomcat-juli.jar" Jul 9, 2013 5:28:08 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-bio-8080"] Jul 9, 2013 5:28:08 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-bio-8009"] Jul 9, 2013 5:28:08 PM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 635 ms Jul 9, 2013 5:28:08 PM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina Jul 9, 2013 5:28:08 PM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.35 Jul 9, 2013 5:28:08 PM org.apache.catalina.startup.HostConfig deployWAR INFO: Deploying web application archive C:\apache-tomcat-7.0.35\webapps\activemq-web-console-5.8.0.war SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/apache-tomcat-7.0.35/webapps/activemq-web-console-5.8.0/WEB-INF/lib/activemq-all-5.8.0.jar!/org/slf4j/impl/Stati cLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/apache-tomcat-7.0.35/webapps/activemq-web-console-5.8.0/WEB-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/Stat icLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] 2013-07-09 17:28:13,389 [ost-startStop-1] INFO WebConsoleStarter - Web console type: properties 2013-07-09 17:28:13,960 [ost-startStop-1] INFO WebConsoleStarter - ActiveMQ WebConsole initialized. 2013-07-09 17:28:14,095 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/createDestination.action] onto handler '/createDest ination.action' 2013-07-09 17:28:14,096 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteDestination.action] onto handler '/deleteDest ination.action' 2013-07-09 17:28:14,097 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/createSubscriber.action] onto handler '/createSubsc riber.action' 2013-07-09 17:28:14,098 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteSubscriber.action] onto handler '/deleteSubsc riber.action' 2013-07-09 17:28:14,099 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/sendMessage.action] onto handler '/sendMessage.acti on' 2013-07-09 17:28:14,100 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/purgeDestination.action] onto handler '/purgeDestin ation.action' 2013-07-09 17:28:14,101 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteMessage.action] onto handler '/deleteMessage. action' 2013-07-09 17:28:14,103 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/copyMessage.action] onto handler '/copyMessage.acti on' 2013-07-09 17:28:14,104 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/moveMessage.action] onto handler '/moveMessage.acti on' 2013-07-09 17:28:14,105 [ost-startStop-1] INFO ndingBeanNameUrlHandlerMapping - Mapped URL path [/deleteJob.action] onto handler '/deleteJob.action' Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\docs Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\examples Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\host-manager Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\manager Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory C:\apache-tomcat-7.0.35\webapps\ROOT Jul 9, 2013 5:28:14 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"] Jul 9, 2013 5:28:14 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-bio-8009"] Jul 9, 2013 5:28:14 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 6642 ms

    讓我們訪問Web控制臺:http:// localhost:8080 / activemq-web-console-5.8.0

    如果出現提示,請使用admin / admin作為用戶名/密碼。 這些是默認的安全設置。 請參考conf目錄中的jetty.xml和jetty-realm.properties。

    如上所示,“經紀人-1”是當前的主經紀人。

    現在,如果要關閉broker-1。 在運行broker-1的Terminal窗口中,按Control + C,您會注意到broker-2獲得了鎖定并成為了主服務器。

    INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked.INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked.INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked.INFO | Database C:\apache-activemq-5.8.0\data\kahadb\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOExceptio n: File 'C:\apache-activemq-5.8.0\data\kahadb\lock' could not be locked.INFO | KahaDB is version 4INFO | Recovering from the journal ...INFO | Recovery replayed 2 operations from the journal in 0.022 seconds.INFO | Apache ActiveMQ 5.8.0 (broker-2, ID:AKUNTAMU-1-28147-1373409767675-0:1) is startingINFO | Listening for connections at: tcp://AKUNTAMU-1:61626?maximumConnections=1000&wireformat.maxFrameSize=104857600INFO | Connector openwire StartedINFO | Apache ActiveMQ 5.8.0 (broker-2, ID:AKUNTAMU-1-28147-1373409767675-0:1) startedINFO | For help or more information please see: http://activemq.apache.orgWARN | Store limit is 102400 mb, whilst the data directory: C:\apache-activemq-5.8.0\data\kahadb only has 38888 mb of usable space ERROR | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\apache-activemq-5.8.0\data\broker-2\tmp_storage only has 38888 mb o f usable spaceINFO | Web console type: embeddedINFO | ActiveMQ WebConsole initialized.INFO | Initializing Spring FrameworkServlet 'dispatcher'INFO | jolokia-agent: No access restrictor found at classpath:/jolokia-access.xml, access to all MBeans is allowed

    讓我們刷新Web控制臺

    您可能會看到,現在主節點是broker-2。

    現在,我們已經看到在故障轉移場景中使用外部Web控制臺在節點之間進行無縫切換,讓我們從消息生產者和使用者的角度來看相同的情況。

    我將使用簡單的消息發布器將50條持久消息發布到隊列中,并讓異步使用者接收這50條消息。 我將在發送消息時引入一些延遲,以便我們可以將主服務器斷開幾次并創建一些故障轉移方案。 目的是了解故障轉移協議如何使節點故障轉移完全透明,從而使應用程序不必處理任何重新連接邏輯。

    這是一個使用ActiveMQConnectionFactory和故障轉移協議的簡單生產者。 請注意下面的代碼片段中突出顯示的故障轉移協議URL。

    package com.akuntamukkala.amqms;import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.Destination; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage;import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.log4j.Logger;public class Producer {private static final Logger log = Logger.getLogger(Producer.class);public static void main(String[] args) throws Exception {// Create a ConnectionFactoryActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61626)");for (int i = 0; i < 50; i++) {log.info("Establishing connection");// Create a ConnectionConnection connection = connectionFactory.createConnection();connection.start();log.info("Connection established");// Create a SessionSession session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);// Create the destination (Topic or Queue)Destination destination = session.createQueue("TEST.FOO");// Create a MessageProducer from the Session to the Topic or QueueMessageProducer producer = session.createProducer(destination);producer.setDeliveryMode(DeliveryMode.PERSISTENT);// Create a messagesString text = "Message Counter : " + i;TextMessage message = session.createTextMessage(text);log.info("Sending message : " + text);producer.send(message);log.info("Sent message : " + text);// Clean upsession.close();connection.close();Thread.sleep(1000);}} }

    這是我交替關閉幾次broker-1和broker-2時執行的日志。

    2013-07-10 11:26:32 INFO Producer:25 - Establishing connection 2013-07-10 11:26:33 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:33 INFO Producer:30 - Connection established 2013-07-10 11:26:33 INFO Producer:47 - Sending message : Message Counter : 0 2013-07-10 11:26:33 INFO Producer:49 - Sent message : Message Counter : 0 2013-07-10 11:26:34 INFO Producer:25 - Establishing connection 2013-07-10 11:26:35 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:35 INFO Producer:30 - Connection established 2013-07-10 11:26:35 INFO Producer:47 - Sending message : Message Counter : 1 2013-07-10 11:26:35 INFO Producer:49 - Sent message : Message Counter : 1 2013-07-10 11:26:35 INFO Producer:25 - Establishing connection 2013-07-10 11:26:36 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:36 INFO Producer:30 - Connection established 2013-07-10 11:26:36 INFO Producer:47 - Sending message : Message Counter : 2 2013-07-10 11:26:36 INFO Producer:49 - Sent message : Message Counter : 2 2013-07-10 11:26:37 INFO Producer:25 - Establishing connection 2013-07-10 11:26:37 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:37 INFO Producer:30 - Connection established 2013-07-10 11:26:37 INFO Producer:47 - Sending message : Message Counter : 3 2013-07-10 11:26:37 INFO Producer:49 - Sent message : Message Counter : 3 2013-07-10 11:26:37 INFO Producer:25 - Establishing connection 2013-07-10 11:26:38 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:38 INFO Producer:30 - Connection established 2013-07-10 11:26:38 INFO Producer:47 - Sending message : Message Counter : 4 2013-07-10 11:26:38 INFO Producer:49 - Sent message : Message Counter : 4 2013-07-10 11:26:39 INFO Producer:25 - Establishing connection 2013-07-10 11:26:39 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:39 INFO Producer:30 - Connection established 2013-07-10 11:26:39 INFO Producer:47 - Sending message : Message Counter : 5 2013-07-10 11:26:39 INFO Producer:49 - Sent message : Message Counter : 5 2013-07-10 11:26:39 INFO Producer:25 - Establishing connection 2013-07-10 11:26:39 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:39 INFO Producer:30 - Connection established 2013-07-10 11:26:39 INFO Producer:47 - Sending message : Message Counter : 6 2013-07-10 11:26:39 INFO Producer:49 - Sent message : Message Counter : 6 2013-07-10 11:26:40 INFO Producer:25 - Establishing connection 2013-07-10 11:26:40 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:40 INFO Producer:30 - Connection established 2013-07-10 11:26:40 INFO Producer:47 - Sending message : Message Counter : 7 2013-07-10 11:26:40 INFO Producer:49 - Sent message : Message Counter : 7 2013-07-10 11:26:40 INFO Producer:25 - Establishing connection 2013-07-10 11:26:40 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:40 INFO Producer:30 - Connection established 2013-07-10 11:26:40 INFO Producer:47 - Sending message : Message Counter : 8 2013-07-10 11:26:40 INFO Producer:49 - Sent message : Message Counter : 8 2013-07-10 11:26:41 INFO Producer:25 - Establishing connection 2013-07-10 11:26:41 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:41 INFO Producer:30 - Connection established 2013-07-10 11:26:41 INFO Producer:47 - Sending message : Message Counter : 9 2013-07-10 11:26:41 INFO Producer:49 - Sent message : Message Counter : 9 2013-07-10 11:26:41 INFO Producer:25 - Establishing connection 2013-07-10 11:26:41 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:41 INFO Producer:30 - Connection established 2013-07-10 11:26:41 INFO Producer:47 - Sending message : Message Counter : 10 2013-07-10 11:26:41 INFO Producer:49 - Sent message : Message Counter : 10 2013-07-10 11:26:42 INFO Producer:25 - Establishing connection 2013-07-10 11:26:43 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:43 INFO Producer:30 - Connection established 2013-07-10 11:26:43 INFO Producer:47 - Sending message : Message Counter : 11 2013-07-10 11:26:43 INFO Producer:49 - Sent message : Message Counter : 11 2013-07-10 11:26:43 INFO Producer:25 - Establishing connection 2013-07-10 11:26:43 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:26:43 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61616) failed, reason: java.net.SocketException: Software caused connection abort: recv failed, attempting to automatically reconnect 2013-07-10 11:26:50 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61626 2013-07-10 11:26:50 INFO Producer:30 - Connection established 2013-07-10 11:26:50 INFO Producer:47 - Sending message : Message Counter : 12 2013-07-10 11:26:50 INFO Producer:49 - Sent message : Message Counter : 12 2013-07-10 11:26:51 INFO Producer:25 - Establishing connection 2013-07-10 11:26:52 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:52 INFO Producer:30 - Connection established 2013-07-10 11:26:52 INFO Producer:47 - Sending message : Message Counter : 13 2013-07-10 11:26:52 INFO Producer:49 - Sent message : Message Counter : 13 2013-07-10 11:26:52 INFO Producer:25 - Establishing connection 2013-07-10 11:26:53 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:53 INFO Producer:30 - Connection established 2013-07-10 11:26:53 INFO Producer:47 - Sending message : Message Counter : 14 2013-07-10 11:26:53 INFO Producer:49 - Sent message : Message Counter : 14 2013-07-10 11:26:54 INFO Producer:25 - Establishing connection 2013-07-10 11:26:54 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:54 INFO Producer:30 - Connection established 2013-07-10 11:26:54 INFO Producer:47 - Sending message : Message Counter : 15 2013-07-10 11:26:54 INFO Producer:49 - Sent message : Message Counter : 15 2013-07-10 11:26:54 INFO Producer:25 - Establishing connection 2013-07-10 11:26:55 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:55 INFO Producer:30 - Connection established 2013-07-10 11:26:55 INFO Producer:47 - Sending message : Message Counter : 16 2013-07-10 11:26:55 INFO Producer:49 - Sent message : Message Counter : 16 2013-07-10 11:26:56 INFO Producer:25 - Establishing connection 2013-07-10 11:26:57 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:57 INFO Producer:30 - Connection established 2013-07-10 11:26:57 INFO Producer:47 - Sending message : Message Counter : 17 2013-07-10 11:26:57 INFO Producer:49 - Sent message : Message Counter : 17 2013-07-10 11:26:57 INFO Producer:25 - Establishing connection 2013-07-10 11:26:58 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:58 INFO Producer:30 - Connection established 2013-07-10 11:26:58 INFO Producer:47 - Sending message : Message Counter : 18 2013-07-10 11:26:58 INFO Producer:49 - Sent message : Message Counter : 18 2013-07-10 11:26:59 INFO Producer:25 - Establishing connection 2013-07-10 11:26:59 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:59 INFO Producer:30 - Connection established 2013-07-10 11:26:59 INFO Producer:47 - Sending message : Message Counter : 19 2013-07-10 11:26:59 INFO Producer:49 - Sent message : Message Counter : 19 2013-07-10 11:26:59 INFO Producer:25 - Establishing connection 2013-07-10 11:26:59 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:26:59 INFO Producer:30 - Connection established 2013-07-10 11:26:59 INFO Producer:47 - Sending message : Message Counter : 20 2013-07-10 11:26:59 INFO Producer:49 - Sent message : Message Counter : 20 2013-07-10 11:27:00 INFO Producer:25 - Establishing connection 2013-07-10 11:27:01 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:01 INFO Producer:30 - Connection established 2013-07-10 11:27:01 INFO Producer:47 - Sending message : Message Counter : 21 2013-07-10 11:27:01 INFO Producer:49 - Sent message : Message Counter : 21 2013-07-10 11:27:01 INFO Producer:25 - Establishing connection 2013-07-10 11:27:01 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:01 INFO Producer:30 - Connection established 2013-07-10 11:27:01 INFO Producer:47 - Sending message : Message Counter : 22 2013-07-10 11:27:01 INFO Producer:49 - Sent message : Message Counter : 22 2013-07-10 11:27:02 INFO Producer:25 - Establishing connection 2013-07-10 11:27:02 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:02 INFO Producer:30 - Connection established 2013-07-10 11:27:02 INFO Producer:47 - Sending message : Message Counter : 23 2013-07-10 11:27:02 INFO Producer:49 - Sent message : Message Counter : 23 2013-07-10 11:27:02 INFO Producer:25 - Establishing connection 2013-07-10 11:27:02 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:02 INFO Producer:30 - Connection established 2013-07-10 11:27:02 INFO Producer:47 - Sending message : Message Counter : 24 2013-07-10 11:27:02 INFO Producer:49 - Sent message : Message Counter : 24 2013-07-10 11:27:03 INFO Producer:25 - Establishing connection 2013-07-10 11:27:03 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:03 INFO Producer:30 - Connection established 2013-07-10 11:27:03 INFO Producer:47 - Sending message : Message Counter : 25 2013-07-10 11:27:03 INFO Producer:49 - Sent message : Message Counter : 25 2013-07-10 11:27:03 INFO Producer:25 - Establishing connection 2013-07-10 11:27:03 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:03 INFO Producer:30 - Connection established 2013-07-10 11:27:03 INFO Producer:47 - Sending message : Message Counter : 26 2013-07-10 11:27:03 INFO Producer:49 - Sent message : Message Counter : 26 2013-07-10 11:27:04 INFO Producer:25 - Establishing connection 2013-07-10 11:27:04 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:06 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61626) failed, reason: java.net.SocketException: Software caused connection abort: recv failed, attempting to automatically reconnect 2013-07-10 11:27:15 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61616 2013-07-10 11:27:15 INFO Producer:30 - Connection established 2013-07-10 11:27:15 INFO Producer:47 - Sending message : Message Counter : 27 2013-07-10 11:27:15 INFO Producer:49 - Sent message : Message Counter : 27 2013-07-10 11:27:16 INFO Producer:25 - Establishing connection 2013-07-10 11:27:17 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:17 INFO Producer:30 - Connection established 2013-07-10 11:27:17 INFO Producer:47 - Sending message : Message Counter : 28 2013-07-10 11:27:17 INFO Producer:49 - Sent message : Message Counter : 28 2013-07-10 11:27:17 INFO Producer:25 - Establishing connection 2013-07-10 11:27:18 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:18 INFO Producer:30 - Connection established 2013-07-10 11:27:18 INFO Producer:47 - Sending message : Message Counter : 29 2013-07-10 11:27:18 INFO Producer:49 - Sent message : Message Counter : 29 2013-07-10 11:27:19 INFO Producer:25 - Establishing connection 2013-07-10 11:27:20 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:20 INFO Producer:30 - Connection established 2013-07-10 11:27:20 INFO Producer:47 - Sending message : Message Counter : 30 2013-07-10 11:27:20 INFO Producer:49 - Sent message : Message Counter : 30 2013-07-10 11:27:20 INFO Producer:25 - Establishing connection 2013-07-10 11:27:20 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:20 INFO Producer:30 - Connection established 2013-07-10 11:27:20 INFO Producer:47 - Sending message : Message Counter : 31 2013-07-10 11:27:20 INFO Producer:49 - Sent message : Message Counter : 31 2013-07-10 11:27:21 INFO Producer:25 - Establishing connection 2013-07-10 11:27:22 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:22 INFO Producer:30 - Connection established 2013-07-10 11:27:22 INFO Producer:47 - Sending message : Message Counter : 32 2013-07-10 11:27:22 INFO Producer:49 - Sent message : Message Counter : 32 2013-07-10 11:27:22 INFO Producer:25 - Establishing connection 2013-07-10 11:27:22 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:22 INFO Producer:30 - Connection established 2013-07-10 11:27:22 INFO Producer:47 - Sending message : Message Counter : 33 2013-07-10 11:27:22 INFO Producer:49 - Sent message : Message Counter : 33 2013-07-10 11:27:23 INFO Producer:25 - Establishing connection 2013-07-10 11:27:23 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:23 INFO Producer:30 - Connection established 2013-07-10 11:27:23 INFO Producer:47 - Sending message : Message Counter : 34 2013-07-10 11:27:23 INFO Producer:49 - Sent message : Message Counter : 34 2013-07-10 11:27:23 INFO Producer:25 - Establishing connection 2013-07-10 11:27:24 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:24 INFO Producer:30 - Connection established 2013-07-10 11:27:24 INFO Producer:47 - Sending message : Message Counter : 35 2013-07-10 11:27:24 INFO Producer:49 - Sent message : Message Counter : 35 2013-07-10 11:27:25 INFO Producer:25 - Establishing connection 2013-07-10 11:27:27 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:27 INFO Producer:30 - Connection established 2013-07-10 11:27:27 INFO Producer:47 - Sending message : Message Counter : 36 2013-07-10 11:27:27 INFO Producer:49 - Sent message : Message Counter : 36 2013-07-10 11:27:27 INFO Producer:25 - Establishing connection 2013-07-10 11:27:28 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:28 INFO Producer:30 - Connection established 2013-07-10 11:27:28 INFO Producer:47 - Sending message : Message Counter : 37 2013-07-10 11:27:28 INFO Producer:49 - Sent message : Message Counter : 37 2013-07-10 11:27:29 INFO Producer:25 - Establishing connection 2013-07-10 11:27:30 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:30 INFO Producer:30 - Connection established 2013-07-10 11:27:30 INFO Producer:47 - Sending message : Message Counter : 38 2013-07-10 11:27:30 INFO Producer:49 - Sent message : Message Counter : 38 2013-07-10 11:27:30 INFO Producer:25 - Establishing connection 2013-07-10 11:27:31 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:27:33 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61616) failed, reason: java.net.SocketException: Software caused connection abort: recv failed, attempting to automatically reconnect 2013-07-10 11:27:38 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61626 2013-07-10 11:27:38 INFO Producer:30 - Connection established 2013-07-10 11:27:38 INFO Producer:47 - Sending message : Message Counter : 39 2013-07-10 11:27:38 INFO Producer:49 - Sent message : Message Counter : 39 2013-07-10 11:27:39 INFO Producer:25 - Establishing connection 2013-07-10 11:27:39 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:39 INFO Producer:30 - Connection established 2013-07-10 11:27:39 INFO Producer:47 - Sending message : Message Counter : 40 2013-07-10 11:27:39 INFO Producer:49 - Sent message : Message Counter : 40 2013-07-10 11:27:39 INFO Producer:25 - Establishing connection 2013-07-10 11:27:40 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:40 INFO Producer:30 - Connection established 2013-07-10 11:27:40 INFO Producer:47 - Sending message : Message Counter : 41 2013-07-10 11:27:40 INFO Producer:49 - Sent message : Message Counter : 41 2013-07-10 11:27:41 INFO Producer:25 - Establishing connection 2013-07-10 11:27:42 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:42 INFO Producer:30 - Connection established 2013-07-10 11:27:42 INFO Producer:47 - Sending message : Message Counter : 42 2013-07-10 11:27:42 INFO Producer:49 - Sent message : Message Counter : 42 2013-07-10 11:27:42 INFO Producer:25 - Establishing connection 2013-07-10 11:27:42 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:42 INFO Producer:30 - Connection established 2013-07-10 11:27:42 INFO Producer:47 - Sending message : Message Counter : 43 2013-07-10 11:27:42 INFO Producer:49 - Sent message : Message Counter : 43 2013-07-10 11:27:43 INFO Producer:25 - Establishing connection 2013-07-10 11:27:44 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:44 INFO Producer:30 - Connection established 2013-07-10 11:27:44 INFO Producer:47 - Sending message : Message Counter : 44 2013-07-10 11:27:44 INFO Producer:49 - Sent message : Message Counter : 44 2013-07-10 11:27:44 INFO Producer:25 - Establishing connection 2013-07-10 11:27:45 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:45 INFO Producer:30 - Connection established 2013-07-10 11:27:45 INFO Producer:47 - Sending message : Message Counter : 45 2013-07-10 11:27:45 INFO Producer:49 - Sent message : Message Counter : 45 2013-07-10 11:27:46 INFO Producer:25 - Establishing connection 2013-07-10 11:27:47 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:47 INFO Producer:30 - Connection established 2013-07-10 11:27:47 INFO Producer:47 - Sending message : Message Counter : 46 2013-07-10 11:27:47 INFO Producer:49 - Sent message : Message Counter : 46 2013-07-10 11:27:48 INFO Producer:25 - Establishing connection 2013-07-10 11:27:48 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:48 INFO Producer:30 - Connection established 2013-07-10 11:27:48 INFO Producer:47 - Sending message : Message Counter : 47 2013-07-10 11:27:48 INFO Producer:49 - Sent message : Message Counter : 47 2013-07-10 11:27:48 INFO Producer:25 - Establishing connection 2013-07-10 11:27:49 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:49 INFO Producer:30 - Connection established 2013-07-10 11:27:49 INFO Producer:47 - Sending message : Message Counter : 48 2013-07-10 11:27:49 INFO Producer:49 - Sent message : Message Counter : 48 2013-07-10 11:27:50 INFO Producer:25 - Establishing connection 2013-07-10 11:27:51 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61626 2013-07-10 11:27:51 INFO Producer:30 - Connection established 2013-07-10 11:27:51 INFO Producer:47 - Sending message : Message Counter : 49 2013-07-10 11:27:51 INFO Producer:49 - Sent message : Message Counter : 49

    這是Web控制臺,顯示排隊的50條消息。

    請勿在上面的屏幕截圖中困擾#Messages Enqueued = 0。 此計數表示自此節點啟動以來已排隊的消息數。 由于我已經在50條消息入隊后重新啟動了該節點,因此計數顯示為0。

    現在讓我們嘗試使用異步使用者使用這些消息,這些使用者使用帶有故障轉移協議的ActiveMQ連接工廠。

    這是使用故障轉移協議的ActiveMQConnectionFactory的簡單異步使用者。

    package com.akuntamukkala.amqms;import javax.jms.Connection; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Session; import javax.jms.TextMessage;import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.log4j.Logger;public class Consumer implements MessageListener {private static final Logger log = Logger.getLogger(Consumer.class);public static void main(String[] args) throws Exception {ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61626)");// Create a ConnectionConnection connection = connectionFactory.createConnection();connection.start();// Create a SessionSession session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);// Create the destination (Topic or Queue)Destination destination = session.createQueue("TEST.FOO");// Create a MessageConsumer from the Session to the QueueMessageConsumer consumer = session.createConsumer(destination);consumer.setMessageListener(new Consumer()); // asynchronous listenerThread.sleep(120000); // long wait to keep program runningconsumer.close();session.close();connection.close();}/*** asynchronous message listener*/public void onMessage(Message message) {try {log.info(((TextMessage) message).getText());Thread.sleep(500);} catch (JMSException e) {log.error(e);} catch (InterruptedException e) {log.error(e);}}}

    這是執行的日志。 我在日志中明顯地切換了主節點幾次。

    2013-07-10 11:46:01 INFO FailoverTransport:1030 - Successfully connected to tcp://localhost:61616 2013-07-10 11:46:01 INFO Consumer:49 - Message Counter : 0 2013-07-10 11:46:02 INFO Consumer:49 - Message Counter : 1 2013-07-10 11:46:02 INFO Consumer:49 - Message Counter : 2 2013-07-10 11:46:03 INFO Consumer:49 - Message Counter : 3 2013-07-10 11:46:03 INFO Consumer:49 - Message Counter : 4 2013-07-10 11:46:04 INFO Consumer:49 - Message Counter : 5 2013-07-10 11:46:04 INFO Consumer:49 - Message Counter : 6 2013-07-10 11:46:05 INFO Consumer:49 - Message Counter : 7 2013-07-10 11:46:05 INFO Consumer:49 - Message Counter : 8 2013-07-10 11:46:06 INFO Consumer:49 - Message Counter : 9 2013-07-10 11:46:06 INFO Consumer:49 - Message Counter : 10 2013-07-10 11:46:07 INFO Consumer:49 - Message Counter : 11 2013-07-10 11:46:07 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61616) failed, reason: java.io.EOFException, attempting to automatically reconnect 2013-07-10 11:46:18 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61626 2013-07-10 11:46:18 WARN ActiveMQMessageConsumer:1348 - Duplicate dispatch on connection: ID:AKUNTAMU-1-2141-1373474760280-1:1 to consumer: ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, ignoring (auto acking) duplicate: MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, destination = queue://TEST.FOO, message = ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:AKUNTAMU-1-1739-1373473592152-1:12:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:AKUNTAMU-1-1739-1373473592152-1:12:1:1, destination = queue://TEST.FOO, transactionId = null, expiration = 0, timestamp = 1373473603281, arrival = 0, brokerInTime = 1373473603281, brokerOutTime = 1373474778676, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = Message Counter : 11}, redeliveryCounter = 0} 2013-07-10 11:46:18 INFO Consumer:49 - Message Counter : 12 2013-07-10 11:46:19 INFO Consumer:49 - Message Counter : 13 2013-07-10 11:46:19 INFO Consumer:49 - Message Counter : 14 2013-07-10 11:46:20 INFO Consumer:49 - Message Counter : 15 2013-07-10 11:46:20 INFO Consumer:49 - Message Counter : 16 2013-07-10 11:46:21 INFO Consumer:49 - Message Counter : 17 2013-07-10 11:46:21 INFO Consumer:49 - Message Counter : 18 2013-07-10 11:46:22 INFO Consumer:49 - Message Counter : 19 2013-07-10 11:46:22 INFO Consumer:49 - Message Counter : 20 2013-07-10 11:46:23 INFO Consumer:49 - Message Counter : 21 2013-07-10 11:46:23 INFO Consumer:49 - Message Counter : 22 2013-07-10 11:46:24 INFO Consumer:49 - Message Counter : 23 2013-07-10 11:46:24 INFO Consumer:49 - Message Counter : 24 2013-07-10 11:46:25 INFO Consumer:49 - Message Counter : 25 2013-07-10 11:46:25 INFO Consumer:49 - Message Counter : 26 2013-07-10 11:46:26 INFO Consumer:49 - Message Counter : 27 2013-07-10 11:46:26 INFO Consumer:49 - Message Counter : 28 2013-07-10 11:46:27 INFO Consumer:49 - Message Counter : 29 2013-07-10 11:46:27 INFO Consumer:49 - Message Counter : 30 2013-07-10 11:46:28 INFO Consumer:49 - Message Counter : 31 2013-07-10 11:46:28 INFO Consumer:49 - Message Counter : 32 2013-07-10 11:46:29 INFO Consumer:49 - Message Counter : 33 2013-07-10 11:46:29 INFO Consumer:49 - Message Counter : 34 2013-07-10 11:46:30 INFO Consumer:49 - Message Counter : 35 2013-07-10 11:46:30 INFO Consumer:49 - Message Counter : 36 2013-07-10 11:46:31 INFO Consumer:49 - Message Counter : 37 2013-07-10 11:46:31 INFO Consumer:49 - Message Counter : 38 2013-07-10 11:46:32 INFO Consumer:49 - Message Counter : 39 2013-07-10 11:46:32 WARN FailoverTransport:255 - Transport (tcp://127.0.0.1:61626) failed, reason: java.io.EOFException, attempting to automatically reconnect 2013-07-10 11:46:43 INFO FailoverTransport:1032 - Successfully reconnected to tcp://localhost:61616 2013-07-10 11:46:43 WARN ActiveMQMessageConsumer:1348 - Duplicate dispatch on connection: ID:AKUNTAMU-1-2141-1373474760280-1:1 to consumer: ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, ignoring (auto acking) duplicate: MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:AKUNTAMU-1-2141-1373474760280-1:1:1:1, destination = queue://TEST.FOO, message = ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:AKUNTAMU-1-1739-1373473592152-1:40:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:AKUNTAMU-1-1739-1373473592152-1:40:1:1, destination = queue://TEST.FOO, transactionId = null, expiration = 0, timestamp = 1373473658595, arrival = 0, brokerInTime = 1373473658599, brokerOutTime = 1373474803745, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = Message Counter : 39}, redeliveryCounter = 0} 2013-07-10 11:46:43 INFO Consumer:49 - Message Counter : 40 2013-07-10 11:46:44 INFO Consumer:49 - Message Counter : 41 2013-07-10 11:46:44 INFO Consumer:49 - Message Counter : 42 2013-07-10 11:46:45 INFO Consumer:49 - Message Counter : 43 2013-07-10 11:46:45 INFO Consumer:49 - Message Counter : 44 2013-07-10 11:46:46 INFO Consumer:49 - Message Counter : 45 2013-07-10 11:46:46 INFO Consumer:49 - Message Counter : 46 2013-07-10 11:46:47 INFO Consumer:49 - Message Counter : 47 2013-07-10 11:46:47 INFO Consumer:49 - Message Counter : 48 2013-07-10 11:46:48 INFO Consumer:49 - Message Counter : 49

    我們來看看ActiveMQ Web控制臺:

    您可能會發現#出隊消息= 11非常有趣。 這是自當前ActiveMQ主節點啟動以來已出隊的消息數。

    結論

    因此,我們看到了以下情況:

  • 在具有共享的基于KahaDB文件的數據庫的主/從配置中運行2個ActiveMQ節點。
  • 將托管在Tomcat實例中的ActiveMQ Web控制臺配置為指向群集中的哪個節點為主節點
  • 故障轉移方案
  • 故障轉移忽略的消息發布者和使用者行為
  • 在以后的博客中,我將發布一些其他有趣的ActiveMQ配置。 敬請關注。

    ActiveMQ'ing快樂!

    資源:

  • http://activemq.apache.org/
  • http://www.jakubkorab.net/category/technology/activemq
  • 翻譯自: https://www.javacodegeeks.com/2014/04/using-activemq-masterslave-configuration-with-failover-protocol.html

    創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

    總結

    以上是生活随笔為你收集整理的使用ActiveMQ –具有故障转移协议的“主/从”配置的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。