Статьи

Использование ActiveMQ — конфигурация «ведущий / ведомый» с протоколом отработки отказа

Вступление

Брокеры ActiveMQ, как правило, являются основной частью инфраструктуры обмена сообщениями на предприятии. Очень важно, чтобы эта инфраструктура обмена сообщениями была высокодоступной и масштабируемой. Пожалуйста, прочитайте эту ссылку , чтобы узнать больше о создании сети брокеров для поддержки различных вариантов использования. Одним из популярных вариантов использования ActiveMQ является конфигурация Master / Slave с общей базой данных. Когда используется эта конфигурация, потребители и производители сообщений могут работать без прерываний, поскольку они используют фабрику соединений ActiveMQ с протоколом отработки отказа. Протокол восстановления после отказа защищает потребителей и производителей от необходимости иметь дело с любой потенциальной логикой простоя или логикой переподключения на уровне приложений, когда подчиненный узел ActiveMQ вступает во владение, чтобы стать главным, что происходит, если текущий главный узел по какой-либо причине выходит из строя. Я должен предупредить, что эта конфигурация не должна использоваться для маскировки любых проблем, которые вынимают главный узел. Мы должны устранить любые причины, которые приводят к незапланированному отключению главного узла.

обзор

В этом блоге я продемонстрирую следующее:

  1. Запустите 2 узла ActiveMQ в конфигурации Master / Slave с общей базой данных на основе файлов KahaDB.
  2. Сконфигурируйте веб-консоль ActiveMQ, размещенную в экземпляре Tomcat, для указания того, какой узел является главным узлом в кластере.
  3. Сценарии отработки отказа.
  4. Издатель сообщения и потребительское поведение не обращают внимания на сбой.

Снимок экрана 2013-07-09 в 11.59.29 вечера

Предпосылки

  1. Установите ActiveMQ версии 5.8.0
  2. Загрузите веб-консоль ActiveMQ версии 5.8.0 отсюда
  3. Установите Tomcat версии 7.0.35 — для размещения приложения веб-консоли ActiveMQ

Глубокое погружение

Мы создадим двухузловой кластер ActiveMQ на том же компьютере с Windows 7. Нам нужно настроить порты (TCP & JMX) таким образом, чтобы не было конфликтов. ActiveMQ предоставляет скрипт под названием «activemq-admin.bat», который помогает запускать несколько экземпляров ActiveMQ с использованием одних и тех же двоичных файлов, очень похожих на Tomcat. Давайте продолжим и создадим экземпляры broker-1 и broker-2.

команда: activemq-admin создать <DIR-for-ActiveMQ-узел>

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
C:\apache-activemq-5.8.0\bin>activemq-admin create ..\cluster\broker-1
 
Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jre
  Heap sizes: current=125632k  free=124976k  max=1864192k
    JVM 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.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-command.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-command.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-demo.xml
          to: 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.xml
          to: 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.xml
          to: 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.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-jdbc.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-scalability.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-scalability.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-security.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-security.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-specjms.xml
          to: 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.xml
          to: 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.xml
          to: 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.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-stomp.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-throughput.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\activemq-throughput.xml
Copying from: C:\apache-activemq-5.8.0\conf\broker-localhost.cert
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker-localhost.cert
Copying from: C:\apache-activemq-5.8.0\conf\broker.ks
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker.ks
Copying from: C:\apache-activemq-5.8.0\conf\broker.ts
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\broker.ts
Copying from: C:\apache-activemq-5.8.0\conf\camel.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\camel.xml
Copying from: C:\apache-activemq-5.8.0\conf\client.ks
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\client.ks
Copying from: C:\apache-activemq-5.8.0\conf\client.ts
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\client.ts
Copying from: C:\apache-activemq-5.8.0\conf\credentials-enc.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\credentials-enc.properties
Copying from: C:\apache-activemq-5.8.0\conf\credentials.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\credentials.properties
Copying from: C:\apache-activemq-5.8.0\conf\jetty-demo.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty-demo.xml
Copying from: C:\apache-activemq-5.8.0\conf\jetty-realm.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty-realm.properties
Copying from: C:\apache-activemq-5.8.0\conf\jetty.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jetty.xml
Copying from: C:\apache-activemq-5.8.0\conf\jmx.access
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jmx.access
Copying from: C:\apache-activemq-5.8.0\conf\jmx.password
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\jmx.password
Copying from: C:\apache-activemq-5.8.0\conf\log4j.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\log4j.properties
Copying from: C:\apache-activemq-5.8.0\conf\logging.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-1\conf\logging.properties

Теперь давайте создадим экземпляр Broker-2 …

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
C:\apache-activemq-5.8.0\bin>activemq-admin create ..\cluster\broker-2
 
Java Runtime: Sun Microsystems Inc. 1.6.0_31 C:\Program Files\Java\jdk1.6.0_31\jre
  Heap sizes: current=125632k  free=124976k  max=1864192k
    JVM 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.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-command.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-command.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-demo.xml
          to: 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.xml
          to: 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.xml
          to: 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.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-jdbc.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-scalability.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-scalability.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-security.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-security.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-specjms.xml
          to: 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.xml
          to: 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.xml
          to: 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.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-stomp.xml
Copying from: C:\apache-activemq-5.8.0\conf\activemq-throughput.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\activemq-throughput.xml
Copying from: C:\apache-activemq-5.8.0\conf\broker-localhost.cert
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker-localhost.cert
Copying from: C:\apache-activemq-5.8.0\conf\broker.ks
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker.ks
Copying from: C:\apache-activemq-5.8.0\conf\broker.ts
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\broker.ts
Copying from: C:\apache-activemq-5.8.0\conf\camel.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\camel.xml
Copying from: C:\apache-activemq-5.8.0\conf\client.ks
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\client.ks
Copying from: C:\apache-activemq-5.8.0\conf\client.ts
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\client.ts
Copying from: C:\apache-activemq-5.8.0\conf\credentials-enc.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\credentials-enc.properties
Copying from: C:\apache-activemq-5.8.0\conf\credentials.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\credentials.properties
Copying from: C:\apache-activemq-5.8.0\conf\jetty-demo.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty-demo.xml
Copying from: C:\apache-activemq-5.8.0\conf\jetty-realm.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty-realm.properties
Copying from: C:\apache-activemq-5.8.0\conf\jetty.xml
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jetty.xml
Copying from: C:\apache-activemq-5.8.0\conf\jmx.access
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jmx.access
Copying from: C:\apache-activemq-5.8.0\conf\jmx.password
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\jmx.password
Copying from: C:\apache-activemq-5.8.0\conf\log4j.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\log4j.properties
Copying from: C:\apache-activemq-5.8.0\conf\logging.properties
          to: C:\apache-activemq-5.8.0\cluster\broker-2\conf\logging.properties

Вы могли заметить следующие свойства выше:

1
2
3
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

Эти свойства должны быть исправлены, поскольку мы хотим, чтобы ACTIVEMQ_BASE и ACTIVEMQ_CONF были разными для broker-1 и broker-2.

Нам нужно отредактировать следующие файлы:

  • broker-1.bat в каталоге C: \ apache-activemq-5.8.0 \ cluster \ broker-1 \ bin
    • set ACTIVEMQ_HOME = ”C: /apache-activemq-5.8.0 ″
    • set ACTIVEMQ_BASE = ”C: /apache-activemq-5.8.0/cluster/broker-1 ″
    • set ACTIVEMQ_CONF =% ACTIVEMQ_BASE% / conf
  • broker-2.bat в каталоге C: \ apache-activemq-5.8.0 \ cluster \ broker-2 \ bin
    • set ACTIVEMQ_HOME = ”C: /apache-activemq-5.8.0 ″
    • set ACTIVEMQ_BASE = ”C: /apache-activemq-5.8.0/cluster/broker-2 ″
    • set ACTIVEMQ_CONF =% ACTIVEMQ_BASE% / conf

Вы можете заметить, что оба узла broker-1 и broker-2 используют одну и ту же папку ACTIVEMQ_DATA. Так как мы используем встроенный KahaDB для постоянства, как брокер-1, так и брокер-2 поделятся этим.

Нам нужно дифференцировать порты tcp для broker-1 и broker-2, а также включить JMX и настроить порты JMX для удаленного мониторинга.

Давайте отредактируем файл activemq.xml для broker-1, чтобы исправить порт tcp:

1
2
3
4
5
<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>

Давайте отредактируем activemq.xml для broker-1, чтобы включить мониторинг JMX, обратите внимание на атрибут useJMX = «true» ниже

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

Давайте настроим порт JMX

1
2
3
<managementContext>
    <managementContext createConnector="true" connectorPort="1099"/>
</managementContext>

Повторите то же самое для брокера-2. установите порт TCP на 61626 и порт JMX на 2099.

Старт брокера-1.

1
 

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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\jre
  Heap sizes: current=1004928k  free=994439k  max=1004928k
    JVM 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.xml
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@71060478: startup date [Tue Jul 09 16:59:15 CDT 2013]; root of context hierarchy
 INFO | PListStore:[C:\apache-activemq-5.8.0\data\broker-1\tmp_storage] started
 INFO | 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/jmxrmi
 INFO | KahaDB is version 4
 INFO | 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 starting
 INFO | Listening for connections at: tcp://AKUNTAMU-1:61616?maximumConnections=1000&wireformat.maxFrameSize=104857600
 INFO | Connector openwire Started
 INFO | Apache ActiveMQ 5.8.0 (broker-1, ID:AKUNTAMU-1-27777-1373407157813-0:1) started
 INFO | For help or more information please see: http://activemq.apache.org
 WARN | 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 space
 INFO | Web console type: embedded
 INFO | 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

Старт брокера-2.

Вы заметите, что брокер-2 не может получить блокировку, так как брокер-1 уже захватил ее. брокер-2 будет повторять попытки захвата блокировки каждые 10 секунд.

1
 

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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\jre
  Heap sizes: current=1004928k  free=994439k  max=1004928k
    JVM 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.xml
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@420f9c40: startup date [Tue Jul 09 17:02:55 CDT 2013]; root of context hierarchy
 INFO | PListStore:[C:\apache-activemq-5.8.0\data\broker-2\tmp_storage] started
 INFO | 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/jmxrmi
 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.

Теперь давайте настроим веб-консоль ActiveMQ.

По умолчанию дистрибутив ActiveMQ содержит веб-консоль администратора, но в конфигурации Master / Slave неизвестно, какой узел является главным. Поэтому нет смысла использовать встроенную веб-консоль. Следовательно, лучше всего иметь веб-консоль ActiveMQ вне узлов ActiveMQ.

Вы можете отключить встроенную веб-консоль ActiveMQ в каждом узле, комментируя следующую строку в файле activemq.xml в каталоге conf каждого узла ActiveMQ.

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

В нашем примере мы развернем веб-приложение ActiveMQ Web Console в контейнере Tomcat, а затем настроим приложение веб-консоли ActiveMQ для интеллектуального указания на главный узел в кластере ActiveMQ.

так что давайте скопируем activemq-web-console-5.8.0.war в каталог webapps Tomcat. Добавьте следующую строку в catalina.bat

1
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.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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: 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

Давайте перейдем к веб-консоли: http: // localhost: 8080 / activemq-web-console-5.8.0

Используйте admin / admin для имени пользователя / пароля, если будет предложено. Это настройки безопасности по умолчанию. Обратитесь к файлам jetty.xml и jetty-realm.properties в каталоге conf.

брокер-1 - Консоль ActiveMQ

Как показано выше, «брокер-1» является текущим главным брокером.

Теперь, если бы вам пришлось выключить брокер-1. Нажмите Control + C в окне терминала, в котором работает broker-1, и вы заметите, что broker-2 получает блокировку и становится мастером.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 4
 INFO | 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 starting
 INFO | Listening for connections at: tcp://AKUNTAMU-1:61626?maximumConnections=1000&wireformat.maxFrameSize=104857600
 INFO | Connector openwire Started
 INFO | Apache ActiveMQ 5.8.0 (broker-2, ID:AKUNTAMU-1-28147-1373409767675-0:1) started
 INFO | For help or more information please see: http://activemq.apache.org
 WARN | 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 space
 INFO | Web console type: embedded
 INFO | 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

Давайте обновим веб-консоль
брокер-2 - Консоль ActiveMQ

Как вы можете заметить, теперь главный узел — broker-2.

Теперь, когда мы увидели плавное переключение между узлами в сценарии отработки отказа с помощью внешней веб-консоли, давайте посмотрим на то же с точки зрения производителя и потребителя сообщений.

Я опубликую 50 постоянных сообщений в очереди, используя простой редактор сообщений, и получу эти 50 сообщений асинхронным потребителем. Я представлю небольшую задержку при отправке сообщений, чтобы мы могли несколько раз отключить мастер и создать несколько сценариев отработки отказа. Цель состоит в том, чтобы увидеть, как протокол аварийного переключения делает прозрачным переключение при отказе узла и таким образом защищает приложение от необходимости иметь дело с любой логикой переподключения.

Вот простой производитель, использующий ActiveMQConnectionFactory с протоколом отработки отказа. Обратите внимание на выделенный URL-адрес протокола отработки отказа в приведенном ниже фрагменте кода.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 ConnectionFactory
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                "failover:(tcp://localhost:61616,tcp://localhost:61626)");
  
        for (int i = 0; i < 50; i++) {
              
            log.info("Establishing connection");
            // Create a Connection
            Connection connection = connectionFactory.createConnection();
            connection.start();
              
            log.info("Connection established");
              
            // Create a Session
            Session 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 Queue
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
  
            // Create a messages
            String text = "Message Counter : " + i;
            TextMessage message = session.createTextMessage(text);
  
            log.info("Sending message : " + text);
            producer.send(message);
            log.info("Sent message : " + text);
            // Clean up
            session.close();
            connection.close();
  
            Thread.sleep(1000);
        }
    }
}

Вот журналы выполнения, пока я выключаю broker-1 и broker-2 поочередно несколько раз.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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

Вот веб-консоль, отображающая 50 сообщений в очереди.

брокер-1 - очереди

Не беспокойтесь о #Messages Enqueued = 0 на скриншоте выше. Этот счетчик представляет количество сообщений, помещенных в очередь с момента запуска этого узла. Поскольку я перезапустил узел после того, как 50 сообщений уже были помещены в очередь, счетчик отображается как 0.

Теперь давайте попробуем использовать эти сообщения с помощью асинхронного потребителя с использованием фабрики соединений ActiveMQ с протоколом отработки отказа.

Вот простой асинхронный потребитель с ActiveMQConnectionFactory, использующий протокол аварийного переключения.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 Connection
        Connection connection = connectionFactory.createConnection();
        connection.start();
  
        // Create a Session
        Session 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 Queue
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(new Consumer()); // asynchronous listener
        Thread.sleep(120000); // long wait to keep program running
        consumer.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);
        }
    }
  
}

Вот журналы с казни. Я несколько раз переключал мастер-узлы, как видно из журналов.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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:

broker-1 - Queues-Failover

Вы можете найти # Messages Dequeued = 11 очень интересным. Это количество сообщений, удаленных с текущего главного узла ActiveMQ с момента его запуска.

Вывод

Таким образом, мы видели следующее в действии:

  1. Запустите 2 узла ActiveMQ в конфигурации Master / Slave с общей базой данных на основе файлов KahaDB.
  2. Настройте веб-консоль ActiveMQ, размещенную в экземпляре Tomcat, для указания того, какой узел является главным узлом в кластере.
  3. Сценарий отработки отказа
  4. Издатель сообщения и потребительское поведение, забывающее об отказе

В будущих блогах я опубликую некоторые другие интересные конфигурации ActiveMQ. Оставайтесь в курсе.

Счастливого ActiveMQ’ing!

Ресурсы:

  1. http://activemq.apache.org/
  2. http://www.jakubkorab.net/category/technology/activemq
Ссылка: Использование ActiveMQ — конфигурация « ведущий / ведомый » с протоколом отработки отказа от нашего партнера JCG Ашвини Кунтамуккала в