ActiveMQ服务故障转移和数据库故障转移

时间:2009-06-30 09:36:07

标签: c# activemq high-availability

我在为ActiveMQ服务实现HA方面遇到了一些困难。 现在,我已经正确实现了Active MQ的Master / Slave代理,所以如果master死了,slave会透明地接管消息传递。它们共享一个Microsoft SQL数据库来存储消息。

我想添加另一个级别的高可用性,确保数据库镜像。像这样,如果主DB服务器死了,代理将切换到镜像服务器。 我已经正确设置了镜像。 (数据正确镜像到辅助DB服务器)。

问题是数据库故障转移会弄乱一切。

如您所知,ActiveMq代理的主/从HA的工作原理如下:主服务器获取数据库中的锁,而从服务器尝试接受它。一旦主设备死机,它就会释放锁定,从设备接管并且客户端切换到新设备。 DB镜像出现问题。当我关闭主数据库服务器时,主服务器无法更新数据库锁。 另一方面,当奴隶无法在主DB服务器中取锁时,会尝试辅助,当然他不能,因为它处于镜像状态。

如果我不使用主/从HA用于activeMQ(那时只有一个代理),则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

2 个答案:

答案 0 :(得分:1)

我认为你需要一种新的主​​/从风格 - 增加了改进 - 见https://issues.apache.org/activemq/browse/AMQ-2387

答案 1 :(得分:0)

请尝试将userName和密码添加到networkConnector。默认,这是:

userName =“system”password =“manager”,经纪人不只是在没有正确权利的情况下转发邮件和队列。