首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何配置Apache下的ActiveMQ内存设置?

如何配置Apache下的ActiveMQ内存设置?
EN

Stack Overflow用户
提问于 2014-01-31 11:37:13
回答 1查看 4.6K关注 0票数 1

我在Apache TomEE下有一个嵌入式TomEE。TomEE在名为tomee.xml的文件中配置JMS,在我的示例中,配置如下

代码语言:javascript
运行
复制
<Resource id="Default JMS Resource Adapter" type="ActiveMQResourceAdapter">
    BrokerXmlConfig = broker:(tcp://localhost:61616)?persistent=true
    ServerUrl = tcp://localhost:61616
    DataSource = MyDataSource
</Resource>

现在,我想指定自定义内存设置,这是在activemq.xml文件中完成的。如果我添加这样的内容,TomEE可以使用Spring加载activemq.xml配置(我认为)

代码语言:javascript
运行
复制
<Resource id="Default JMS Resource Adapter" type="ActiveMQResourceAdapter">
    BrokerXmlConfig = xbean:file:conf/activemq.xml
    ServerUrl = tcp://localhost:61616
    DataSource = MyDataSource
</Resource>

请参阅http://tomee.apache.org/jms-resources-and-mdb-container.html

是那么回事吗?

我已经将5 jars添加到tomee的lib路径中,正如上面的链接所示。

然后,我有一个像这样的activemq.xml

代码语言:javascript
运行
复制
<!-- 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. -->
<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.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.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.conf}/credentials.properties</value>
        </property>
    </bean>
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry queue=">" producerFlowControl="false" prioritizedMessages="true" useCache="false" expireMessagesPeriod="0" queuePrefetch="1" />
                    <pendingQueuePolicy>
                        <vmQueueCursor />
                    </pendingQueuePolicy>
                </policyEntries>
            </policyMap>
        </destinationPolicy>

        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="128 mb" />
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb" />
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb" />
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <transportConnectors>
            <transportConnector name="anythingHere" uri="broker:(tcp://localhost:61616)?persistent=true"/>
        </transportConnectors>
    </broker>
</beans>

但是很明显,我在这里做了一些错误的事情,因为JMS不会启动并返回如下的错误消息

代码语言:javascript
运行
复制
SEVERE: Failed to connect to broker [tcp://localhost:61616]: Could not connect to
broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused
javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason:
java.net.ConnectException: Connection refused

我在这里错过了什么?

更新-更多信息

然后我将绝对路径添加到activemq.xml文件中,因为我无法使它在eclipse内部工作(我知道,这可能更像是eclipse的错误)

然后,我更改了一些无效的XML,例如

代码语言:javascript
运行
复制
<!--             <destinationPolicy> -->
<!--                 <policyMap> -->
<!--                     <policyEntries> -->
<!--                         <policyEntry queue=">" producerFlowControl="false" prioritizedMessages="true" useCache="false" expireMessagesPeriod="0" queuePrefetch="1" /> -->
<!--                         <pendingQueuePolicy> -->
<!--                             <vmQueueCursor /> -->
<!--                         </pendingQueuePolicy> -->
<!--                     </policyEntries> -->
<!--                 </policyMap> -->
<!--             </destinationPolicy> -->

并替换为站点的默认设置

代码语言:javascript
运行
复制
<destinationPolicy>
        <policyMap>
          <policyEntries>
            <policyEntry topic=">" producerFlowControl="true">
                <!-- The constantPendingMessageLimitStrategy is used to prevent
                     slow topic consumers to block producers and affect other consumers
                     by limiting the number of messages that are retained
                     For more information, see:

                     http://activemq.apache.org/slow-consumer-handling.html

                -->
              <pendingMessageLimitStrategy>
                <constantPendingMessageLimitStrategy limit="1000"/>
              </pendingMessageLimitStrategy>
            </policyEntry>
            <policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb">
              <!-- Use VM cursor for better latency
                   For more information, see:

                   http://activemq.apache.org/message-cursors.html

              <pendingQueuePolicy>
                <vmQueueCursor/>
              </pendingQueuePolicy>
              -->
            </policyEntry>
          </policyEntries>
        </policyMap>
    </destinationPolicy>

在从maven存储库中添加kahadb并从activemq-all切换到activemq-spring并将bean定义为activemq.xml之后

代码语言:javascript
运行
复制
    </broker>

    <bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
        <property name="username" value="xxx"/>
        <property name="password" value="xxx"/>
        <property name="poolPreparedStatements" value="true"/>
      </bean>

</beans>

终于..。我又犯了一个错误

代码语言:javascript
运行
复制
SEVERE: Failed to load: URL [file:/home/leoks/EclipseIndigo/workspace2/Servers     /TomEE1.6.0-STABLE-config/activemq.xml], reason: Error creating bean with name  'org.apache.activemq.xbean.XBeanBrokerService#0' defined in URL [file:/home/leoks /EclipseIndigo/workspace2/Servers/TomEE1.6.0-STABLE-config/activemq.xml]: Invocation of init method failed; nested exception is java.io.IOException: Transport Connector could not be registered in JMX: Transport scheme NOT recognized: [broker]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in URL [file:/home/leoks/EclipseIndigo/workspace2/Servers/TomEE1.6.0-STABLE-config/activemq.xml]: Invocation of init method failed; nested exception is java.io.IOException: Transport Connector could not be registered in JMX: Transport scheme NOT recognized: [broker]

在google之后,有些解决方案似乎与activemq无法加载XML有关(这是合理的,因为XML是96年发明的,大约20年前发明的)。

我脱发了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-31 12:27:26

我认为您的传输连接器配置应该如下所示:

代码语言:javascript
运行
复制
<transportConnectors>
    <transportConnector name="tcp" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>

参见连接器的文档

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21479156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档