2

ActiveMQ サービスの HA を実装するのに少し問題があります。現在、Active MQ のマスター/スレーブ ブローカーを正しく実装しているため、マスターが停止すると、スレーブが透過的にメッセージ配信を引き継ぎます。どちらも Microsoft SQL データベースを共有してメッセージを保存します。

データベースのミラーリングを確実にするために、別のレベルの高可用性を追加したいと考えていました。このように、プリンシパル DB サーバーが停止すると、ブローカーはミラー化されたサーバーに切り替わります。ミラーリングを正しくセットアップしました。(データはセカンダリ DB サーバーに正しくミラーリングされます)。

問題は、DB フェイルオーバーがすべてを台無しにすることです。

ご存じのとおり、ActiveMq ブローカーのマスター/スレーブ HA は次のように機能します。マスターは DB のロックを取得し、スレーブはそれを取得しようとします。マスターが停止するとすぐにロックが解放され、スレーブが引き継ぎ、クライアントは新しいマスターに切り替わります。DB ミラーリングに問題があります。プリンシパル DB サーバーをシャットダウンすると、マスターはデータベース ロックの更新に失敗します。一方、スレーブは、プリンシパル DB サーバーでロックを取得できない場合、セカンダリを試行しますが、ミラーリングされた状態であるため、もちろんできません。

ActiveMQ にマスター/スレーブ HA を使用しない場合 (その場合は 1 つのブローカーのみ)、DB ミラーリングは機能します。

マスターの構成ファイルとログは次のとおりです。

<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<!-- START SNIPPET: example -->
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd   
  http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="locations">
            <value>file:${activemq.base}/conf/credentials.properties</value>
         </property>      
    </bean>

    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="MASTER.IP" dataDirectory="${activemq.base}/data">

        <!-- Destination specific policies using destination names or wildcards -->
        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry queue=">" memoryLimit="5mb"/>
                    <policyEntry topic=">" producerFlowControl="false" memoryLimit="5mb">
                    </policyEntry>
                </policyEntries>
            </policyMap>
        </destinationPolicy>

        <!-- Use the following to configure how ActiveMQ is exposed in JMX -->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <!-- The store and forward broker networks ActiveMQ will listen to -->
        <networkConnectors>
            <networkConnector 
                name="HA Queue"
                uri="static:failover:(tcp://MASTER.IP:61616,tcp://SLAVE.IP:61616)"
                />
        </networkConnectors>

        <persistenceAdapter>
            <amqPersistenceAdapter syncOnWrite="false" directory="${activemq.base}/data" maxFileLength="20 mb"/>
        </persistenceAdapter>

        <persistenceAdapter>
                <journaledJDBC journalLogFiles="5" dataDirectory="../activemq-data" dataSource="#mssql-ds"/>
        </persistenceAdapter>

        <sslContext>
            <sslContext keyStore="file:${activemq.base}/conf/broker.ks" keyStorePassword="password" trustStore="file:${activemq.base}/conf/broker.ts" trustStorePassword="password"/>
        </sslContext>

        <!--  The maximum about of space the broker will use before slowing down producers -->
        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb" name="foo"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <!-- The transport connectors ActiveMQ will listen to -->
        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://MASTER.IP:61616"/>
            <transportConnector name="ssl" uri="ssl://MASTER.IP:61617"/>
            <transportConnector name="stomp" uri="stomp://MASTER.IP:61613"/>
            <transportConnector name="xmpp" uri="xmpp://MASTER.IP:61222"/>
        </transportConnectors>
    </broker>

    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">

        <!-- You can use a <package> element for each root package to search for Java routes -->
        <package>org.foo.bar</package>

        <!-- You can use Spring XML syntax to define the routes here using the <route> element -->
        <route>
            <from uri="activemq:example.A"/>
            <to uri="activemq:example.B"/>
        </route>
    </camelContext>

    <!-- configure the camel activemq component to use the current broker -->
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
        <property name="connectionFactory">
          <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="vm://localhost?create=false&amp;waitForStart=10000" />
            <property name="userName" value="${activemq.username}"/>
            <property name="password" value="${activemq.password}"/>
          </bean>
        </property>
    </bean>

    <!-- An embedded servlet engine for serving up the Admin console -->
    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161"/>
        </connectors>

        <handlers>
            <webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
            <webAppContext contextPath="/demo" resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/>
            <webAppContext contextPath="/fileserver" resourceBase="${activemq.base}/webapps/fileserver" logUrlOnStart="true"/>
        </handlers>
    </jetty>

    <!-- MSSQL Setup -->
    <bean id="mssql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
        <property name="url" value="jdbc:sqlserver://PRINCIPALDBSERVER;databaseName=activemq;instanceName=PRINCIPAL;user=activemq;password=activemq;failoverPartner=MIRRORDBSERVER\MIRROR"/>
    </bean>
</beans>

そしてマスターの出力:

wrapper  | --> Wrapper Started as Console
wrapper  | Launching a JVM...
jvm 1    | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1    |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
jvm 1    | 
jvm 1    | ACTIVEMQ_HOME: ..\..
jvm 1    | ACTIVEMQ_BASE: ..\..
jvm 1    | Loading message broker from: xbean:activemq.xml
jvm 1    | INFO  DefaultCamelContext            - JMX enabled. Using InstrumentationLifecycleStrategy.
jvm 1    | INFO  BrokerService                  - Using Persistence Adapter: JournalPersistenceAdapator(JDBCPersistenceAdaptor(org.apache.commons.dbcp.BasicDataSource@15b1773))
jvm 1    | INFO  JDBCPersistenceAdapter         - Database driver recognized: [microsoft_sql_server_2005_jdbc_driver]
jvm 1    | INFO  DefaultDatabaseLocker          - Attempting to acquire the exclusive lock to become the Master broker
jvm 1    | INFO  DefaultDatabaseLocker          - Becoming the master on dataSource: org.apache.commons.dbcp.BasicDataSource@15b1773
jvm 1    | INFO  BrokerService                  - ActiveMQ 5.3-SNAPSHOT JMS Message Broker (MASTER.IP) is starting
jvm 1    | INFO  BrokerService                  - For help or more information please see: http://activemq.apache.org/
jvm 1    | INFO  JournalPersistenceAdapter      - Journal Recovery Started from: Active Journal: using 5 x 20.0 Megs at: C:\Documents and Settings\user\Desktop\apache-activemq-HA\bin\activemq-data\journal
jvm 1    | INFO  JournalPersistenceAdapter      - Journal Recovered: 0 message(s) in transactions recovered.
jvm 1    | INFO  TransportServerThreadSupport   - Listening for connections at: tcp://MASTER.IP:61616
jvm 1    | INFO  TransportConnector             - Connector openwire Started
jvm 1    | INFO  TransportServerThreadSupport   - Listening for connections at: ssl://MASTER.IP:61617
jvm 1    | INFO  TransportConnector             - Connector ssl Started
jvm 1    | INFO  TransportServerThreadSupport   - Listening for connections at: stomp://MASTER.IP:61613
jvm 1    | INFO  TransportConnector             - Connector stomp Started
jvm 1    | INFO  TransportServerThreadSupport   - Listening for connections at: xmpp://MASTER.IP:61222
jvm 1    | INFO  TransportConnector             - Connector xmpp Started
jvm 1    | INFO  DiscoveryNetworkConnector      - Establishing network connection from vm://MASTER.IP to failover:(tcp://MASTER.IP:61616,tcp://SLAVE.IP:61616)
jvm 1    | INFO  TransportConnector             - Connector vm://MASTER.IP Started
jvm 1    | INFO  FailoverTransport              - Successfully connected to tcp://MASTER.IP:61616
jvm 1    | INFO  NetworkConnector               - Network Connector HA Queue Started
jvm 1    | INFO  BrokerService                  - ActiveMQ JMS Message Broker (MASTER.IP, ID:1487-1246351329984-0:0) started
jvm 1    | INFO  DemandForwardingBridge         - Disconnecting loop back connection.
jvm 1    | INFO  TransportConnector             - Connector vm://MASTER.IP Stopped
jvm 1    | INFO  DemandForwardingBridge         - MASTER.IP bridge to MASTER.IP stopped
jvm 1    | INFO  log                            - Logging to org.slf4j.impl.JCLLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
jvm 1    | INFO  log                            - jetty-6.1.9
jvm 1    | INFO  WebConsoleStarter              - ActiveMQ WebConsole initialized.
jvm 1    | INFO  /admin                         - Initializing Spring FrameworkServlet 'dispatcher'
jvm 1    | INFO  log                            - ActiveMQ Console at http://0.0.0.0:8161/admin
jvm 1    | INFO  log                            - ActiveMQ Web Demos at http://0.0.0.0:8161/demo
jvm 1    | INFO  log                            - RESTful file access application at http://0.0.0.0:8161/fileserver
jvm 1    | INFO  log                            - Started SelectChannelConnector@0.0.0.0:8161
jvm 1    | WARN  BrokerRegistry                 - Broker localhost not started so using MASTER.IP instead
jvm 1    | INFO  TransportConnector             - Connector vm://localhost Started
jvm 1    | ERROR DefaultDatabaseLocker          - Failed to update database lock: com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error
jvm 1    | com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1509)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSChannel.write(IOBuffer.java:1563)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSWriter.flush(IOBuffer.java:2422)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSWriter.writePacket(IOBuffer.java:2303)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSWriter.endMessage(IOBuffer.java:1910)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4327)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:369)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:322)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4003)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1550)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:160)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:133)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:290)
jvm 1    |  at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
jvm 1    |  at org.apache.activemq.store.jdbc.DefaultDatabaseLocker.keepAlive(DefaultDatabaseLocker.java:118)
jvm 1    |  at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.databaseLockKeepAlive(JDBCPersistenceAdapter.java:499)
jvm 1    |  at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter$1.run(JDBCPersistenceAdapter.java:201)
jvm 1    |  at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
jvm 1    |  at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
jvm 1    |  at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
jvm 1    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
jvm 1    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
jvm 1    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
jvm 1    |  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
jvm 1    |  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
jvm 1    |  at java.lang.Thread.run(Unknown Source)
jvm 1    | INFO  JDBCPersistenceAdapter         - No longer able to keep the exclusive lock so giving up being a master
jvm 1    | INFO  BrokerService                  - ActiveMQ Message Broker (MASTER.IP, ID:11487-1246351329984-0:0) is shutting down
jvm 1    | INFO  NetworkConnector               - Network Connector HA Queue Stopped
jvm 1    | INFO  TransportConnector             - Connector openwire Stopped
jvm 1    | INFO  TransportConnector             - Connector ssl Stopped
jvm 1    | INFO  TransportConnector             - Connector stomp Stopped
jvm 1    | INFO  TransportConnector             - Connector xmpp Stopped
jvm 1    | ERROR JournalPersistenceAdapter      - Failed to checkpoint a message store: java.util.concurrent.ExecutionException: java.io.IOException: Connection reset by peer: socket write error
jvm 1    | java.util.concurrent.ExecutionException: java.io.IOException: Connection reset by peer: socket write error
jvm 1    |  at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
jvm 1    |  at java.util.concurrent.FutureTask.get(Unknown Source)
jvm 1    |  at org.apache.activemq.store.journal.JournalPersistenceAdapter.doCheckpoint(JournalPersistenceAdapter.java:421)
jvm 1    |  at org.apache.activemq.store.journal.JournalPersistenceAdapter$1.iterate(JournalPersistenceAdapter.java:124)
jvm 1    |  at org.apache.activemq.thread.DedicatedTaskRunner.runTask(DedicatedTaskRunner.java:98)
jvm 1    |  at org.apache.activemq.thread.DedicatedTaskRunner$1.run(DedicatedTaskRunner.java:36)
jvm 1    | Caused by: java.io.IOException: Connection reset by peer: socket write error
jvm 1    |  at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:45)
jvm 1    |  at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:61)
jvm 1    |  at org.apache.activemq.store.jdbc.TransactionContext.begin(TransactionContext.java:151)
jvm 1    |  at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.beginTransaction(JDBCPersistenceAdapter.java:397)
jvm 1    |  at org.apache.activemq.store.journal.JournalPersistenceAdapter.beginTransaction(JournalPersistenceAdapter.java:216)
jvm 1    |  at org.apache.activemq.util.TransactionTemplate.run(TransactionTemplate.java:41)
jvm 1    |  at org.apache.activemq.store.journal.JournalMessageStore.checkpoint(JournalMessageStore.java:258)
jvm 1    |  at org.apache.activemq.store.journal.JournalMessageStore.checkpoint(JournalMessageStore.java:233)
jvm 1    |  at org.apache.activemq.store.journal.JournalPersistenceAdapter$4.call(JournalPersistenceAdapter.java:391)
jvm 1    |  at org.apache.activemq.store.journal.JournalPersistenceAdapter$4.call(JournalPersistenceAdapter.java:389)
jvm 1    |  at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
jvm 1    |  at java.util.concurrent.FutureTask.run(Unknown Source)
jvm 1    |  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
jvm 1    |  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
jvm 1    |  at java.lang.Thread.run(Unknown Source)
jvm 1    | Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1509)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSChannel.write(IOBuffer.java:1563)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSWriter.flush(IOBuffer.java:2422)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSWriter.writePacket(IOBuffer.java:2303)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSWriter.endMessage(IOBuffer.java:1910)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4327)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4310)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection$1ConnectionCommand.doExecute(SQLServerConnection.java:1588)
jvm 1    |  at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4003)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1550)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectionCommand(SQLServerConnection.java:1593)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.setAutoCommit(SQLServerConnection.java:1746)
jvm 1    |  at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
jvm 1    |  at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317)
jvm 1    |  at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:57)
jvm 1    |  ... 13 more
jvm 1    | ERROR JournalPersistenceAdapter      - Could not stop service: JournalPersistenceAdapator(JDBCPersistenceAdaptor(org.apache.commons.dbcp.BasicDataSource@15b1773)). Reason: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
jvm 1    | com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:130)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(SQLServerConnection.java:294)
jvm 1    |  at com.microsoft.sqlserver.jdbc.SQLServerConnection.rollback(SQLServerConnection.java:1791)
jvm 1    |  at org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:328)
jvm 1    |  at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:312)
jvm 1    |  at org.apache.activemq.store.jdbc.DefaultDatabaseLocker.stop(DefaultDatabaseLocker.java:107)
jvm 1    |  at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.stop(JDBCPersistenceAdapter.java:234)
jvm 1    |  at org.apache.activemq.store.journal.JournalPersistenceAdapter.stop(JournalPersistenceAdapter.java:281)
jvm 1    |  at org.apache.activemq.util.ServiceStopper.stop(ServiceStopper.java:41)
jvm 1    |  at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:513)
jvm 1    |  at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.stopBroker(JDBCPersistenceAdapter.java:515)
jvm 1    |  at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.databaseLockKeepAlive(JDBCPersistenceAdapter.java:507)
jvm 1    |  at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter$1.run(JDBCPersistenceAdapter.java:201)
jvm 1    |  at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
jvm 1    |  at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
jvm 1    |  at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
jvm 1    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
jvm 1    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
jvm 1    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
jvm 1    |  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
jvm 1    |  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
jvm 1    |  at java.lang.Thread.run(Unknown Source)
jvm 1    | INFO  BrokerService                  - ActiveMQ JMS Message Broker (MASTER.IP, ID:11487-1246351329984-0:0) stopped
jvm 1    | WARN  JDBCPersistenceAdapter         - Failure occured while stopping broker
wrapper  | <-- Wrapper Stopped

スレーブの構成ファイル:

<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<!-- START SNIPPET: example -->
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd   
  http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="locations">
            <value>file:${activemq.base}/conf/credentials.properties</value>
         </property>      
    </bean>

    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="SLAVE.IP" dataDirectory="${activemq.base}/data">

        <!-- Destination specific policies using destination names or wildcards -->
        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry queue=">" memoryLimit="5mb"/>
                    <policyEntry topic=">" memoryLimit="5mb"/>
                </policyEntries>
            </policyMap>
        </destinationPolicy>

        <!-- Use the following to configure how ActiveMQ is exposed in JMX -->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <!-- The store and forward broker networks ActiveMQ will listen to -->
        <networkConnectors>
            <networkConnector name="HA Queue"
            uri="static:failover:(tcp://SLAVE.IP:61616,tcp://MASTER.IP:61616)"/>
        </networkConnectors>

        <persistenceAdapter>
            <amqPersistenceAdapter syncOnWrite="false" directory="${activemq.base}/data" maxFileLength="20 mb"/>
        </persistenceAdapter>

        <persistenceAdapter>
                <journaledJDBC journalLogFiles="5" dataDirectory="../activemq-data" dataSource="#mssql-ds"/>
        </persistenceAdapter>

        <sslContext>
            <sslContext keyStore="file:${activemq.base}/conf/broker.ks" keyStorePassword="password" trustStore="file:${activemq.base}/conf/broker.ts" trustStorePassword="password"/>
        </sslContext>

        <!--  The maximum about of space the broker will use before slowing down producers -->
        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb" name="foo"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>


        <!-- The transport connectors ActiveMQ will listen to -->
        <transportConnectors>
           <!-- <transportConnector name="openwire" uri="tcp://10.216.1.52:61616" discoveryUri="multicast://default"/> -->
            <transportConnector name="openwire" uri="tcp://SLAVE.IP:61616"/>
            <transportConnector name="ssl" uri="ssl://SLAVE.IP:61617"/>
            <transportConnector name="stomp" uri="stomp://SLAVE.IP:61613"/>
            <transportConnector name="xmpp" uri="xmpp://SLAVE.IP:61222"/>
        </transportConnectors>

    </broker>

    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">

        <!-- You can use a <package> element for each root package to search for Java routes -->
        <package>org.foo.bar</package>

        <!-- You can use Spring XML syntax to define the routes here using the <route> element -->
        <route>
            <from uri="activemq:example.A"/>
            <to uri="activemq:example.B"/>
        </route>
    </camelContext>

     <!-- configure the camel activemq component to use the current broker -->
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
        <property name="connectionFactory">
          <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="vm://localhost?create=false&amp;waitForStart=10000" />
            <property name="userName" value="${activemq.username}"/>
            <property name="password" value="${activemq.password}"/>
          </bean>
        </property>
    </bean>

    <!-- An embedded servlet engine for serving up the Admin console -->
    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161"/>
        </connectors>

        <handlers>
            <webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
            <webAppContext contextPath="/demo" resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/>
            <webAppContext contextPath="/filese
4

2 に答える 2

1

マスター/スレーブの新しいフレーバーが必要だと思います-改善が追加されました-https://issues.apache.org/activemq/browse/AMQ-2387を参照してください

于 2009-09-11T11:35:17.940 に答える
0

networkConnectorにuserNameとpasswordを追加してみてください。デフォルト、これは次のとおりです。

userName = "system" password = "manager"、ブローカーは正しい権限なしでメッセージとキューを転送するだけではありません。

于 2009-09-16T21:07:28.210 に答える