gpt4 book ai didi

java - 如何在 Apache Tomee 下配置 ActiveMQ 内存设置?

转载 作者:行者123 更新时间:2023-11-29 05:29:56 24 4
gpt4 key购买 nike

我在 Apache TomEE 下有一个嵌入式 ActiveMQ。 TomEE 在名为 tomee.xml 的文件中配置 JMS,在我的例子中,它是这样配置的

<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 XBeans 加载 activemq.xml 配置,就像这样(我认为)

<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 个 jar 添加到 tomee 的 lib 路径中,正如上面的链接所示。

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

<!-- 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 没有启动并返回类似这样的错误消息

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,例如

<!--             <destinationPolicy> -->
<!-- <policyMap> -->
<!-- <policyEntries> -->
<!-- <policyEntry queue=">" producerFlowControl="false" prioritizedMessages="true" useCache="false" expireMessagesPeriod="0" queuePrefetch="1" /> -->
<!-- <pendingQueuePolicy> -->
<!-- <vmQueueCursor /> -->
<!-- </pendingQueuePolicy> -->
<!-- </policyEntries> -->
<!-- </policyMap> -->
<!-- </destinationPolicy> -->

并替换为网站的默认值

<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 之后

    </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>

最后....我收到一个新错误

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]

一些谷歌之后,一些解决方案似乎与 activemq 无法加载 XML 有某种关系(有道理,因为 XML 是一项最近的技术,发明于 96 年,差不多 20 年前)

我正在拔头发。

最佳答案

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

<transportConnectors>
<transportConnector name="tcp" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>

参见 documentation用于连接器。

关于java - 如何在 Apache Tomee 下配置 ActiveMQ 内存设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21479156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com