如何在 TomEE 中更改 ActiveMQ KahaDB 目录

问题描述 投票:0回答:3

从 TomEE 9 控制台我可以看到 activeMQ KahaDB 使用

C:\Windows\system32\activemq-data\localhost\KahaDB
作为其默认存储目录。

Jun 29, 2023 10:00:01 AM org.apache.activemq.broker.BrokerService <clinit>
INFO: Loaded the Bouncy Castle security provider at position: 14
Jun 29, 2023 10:00:02 AM org.apache.activemq.broker.BrokerService 
doStartPersistenceAdapter
INFO: Using Persistence Adapter: 
KahaDBPersistenceAdapter[C:\Windows\system32\activemq-data\localhost\KahaDB]
Jun 29, 2023 10:00:02 AM org.apache.activemq.store.SharedFileLocker doStart
INFO: Database activemq-data\localhost\KahaDB\lock is locked by another server. This broker is now in slave mode waiting a lock to be acquired

由于

C:\Windows\system32
是受保护的文件夹,因此会导致 ActiveMQ 分离出此信息

INFO: Database activemq-data\localhost\KahaDB\lock is locked by another server. This broker is now in slave mode waiting a lock to be acquired

我发现此链接记录了如何自定义配置KahaDB。配置看起来很简单,但是 我只是不知道将配置放在哪个xml文件中?我尝试了

server.xml
但没有成功。

以下是server.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  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.
--><!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
  <Server port="18005" shutdown="SHUTDOWN">
  <!-- TomEE plugin for Tomcat -->
  <Listener className="org.apache.tomee.catalina.ServerListener"/>
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!-- APR library loader. Documentation at /docs/apr.html -->
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
    
  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         HTTP Connector: /docs/config/http.html
         AJP  Connector: /docs/config/ajp.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector connectionTimeout="20000" port="18080" protocol="HTTP/1.1" redirectPort="18443" server="Apache TomEE" xpoweredBy="false"/>
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="18080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="18443" />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="18443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" xpoweredBy="false" server="Apache TomEE" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 18009 -->
    <!--
    <Connector protocol="AJP/1.3"
               address="::1"
               port="18009"
               redirectPort="18443" />
    -->

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine defaultHost="localhost" name="Catalina">

      <broker brokerName="broker">
        <persistenceAdapter>
            <kahaDB directory="/var/apps/apache-tomee-plus-9.0/boss/usmo/Boss/resources/jmsQueues" journalMaxFileLength="32mb"/>
        </persistenceAdapter>
      </broker>
    
      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>

      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>

      <Context docBase="Boss" path="/Boss" reloadable="true" source="org.eclipse.jst.jee.server:Boss"/><Context docBase="dhiveCommandXML" path="/dhiveCommandXML" reloadable="true" source="org.eclipse.jst.jee.server:dhiveCommandXML"/></Host>
    </Engine>
  </Service>
</Server>
activemq apache-tomee
3个回答
1
投票

server.xml
是放置KahaDB配置的正确位置。如果这不起作用,请继续发布您的整个
server.xml
和启动日志,让我们看一下。关键是您必须编辑现有的持久性适配器部分,如下所示:

<broker>
....

 <persistenceAdapter>
  <kahaDB directory="c:\var\activemq\data\kahadb" journalMaxFileLength="32mb" />
 </persistenceAdapter>

...
</broker>

请注意,日志目录也会遇到同样的问题。最好将整个 activemq 安装放在

system32
以外的地方。

编辑

我误解了这个 activemq 实例是 TomEE 运行时的一部分。

server.xml
不是正确的地方。答案有点复杂。

首先,对于 ActiveMQ 的任何正式部署,我都会在外部运行代理。这只是一种很好的做法,但如果您只有一台 TomEE 服务器,则使用嵌入式实例就可以了。要配置此功能,请将以下内容放入

tomee.xml
并根据您的需要调整大小。

    <Resource
        id="ra/activemq"
        type="ActiveMQResourceAdapter">
        BrokerXmlConfig=
        ServerUrl=ssl://your.activemq.host.com:61616
        threadPoolSize=10
        maximumRedeliveries=0
    </Resource>
    <Resource
        id="jms/xaConnectionFactory"
        type="javax.jms.ConnectionFactory">
        ResourceAdapter=ra/activemq
        poolMaxSize=10
        poolMinSize=1
        connectionMaxWaitTime=5s
        transactionSupport=xa
    </Resource>

如果您确实想运行本地代理并想配置它,则需要使用您想要的任何设置创建一个

activemq.xml
。首先从 git master 复制
activemq.xml
,然后更改您想要的设置。在这种情况下,您将更改 kahadb 位置。

接下来告诉 TomEE 使用您的配置,您需要从 xml 加载代理配置:

    <Resource
        id="ra/activemq"
        type="ActiveMQResourceAdapter">
        BrokerXmlConfig=xbean:activemq.xml
        ServerUrl=vm://localhost
        threadPoolSize=10
        maximumRedeliveries=0
    </Resource>
    <Resource
        id="jms/xaConnectionFactory"
        type="javax.jms.ConnectionFactory">
        ResourceAdapter=ra/activemq
        poolMaxSize=10
        poolMinSize=1
        connectionMaxWaitTime=5s
        transactionSupport=xa
    </Resource>
  • 您可能需要将一些 jar 文件添加到
    tomee/lib
    目录以获得 XML 配置支持。您可以从 activemq 下载中获取这些
  • vm://localhost
    表示连接到本地代理。确保您的经纪人名称是
    localhost
    ,或者在两个地方都更改它。

希望这有帮助!


1
投票

终于能够配置 TOMEE activemq 以使用不同的 KahaDB 文件夹。我按照 document 中的说明进行操作(请参阅“带有 activemq.xml 的内部 ActiveMQ 代理”部分)。以下是说明的简短摘要和一些附加说明:

  1. 下载以下 jar 并将其添加到 tomee 服务器的 lib 文件夹中:
spring-beans-3.2.9.RELEASE.jar
spring-context-3.2.9.RELEASE.jar
spring-core-3.2.9.RELEASE.jar
spring-web-3.2.9.RELEASE.jar
xbean-spring-3.9.jar
activemq-spring-5.8.0.jar (This one is not mentioned in the document)
activemq_spring-expression-5.3.29.jar (This one is not mentioned in the document)
  1. 将tomee.xml添加到tomee服务器的conf文件夹中。请参阅下面的示例。注意:BrokerXmlConfig 是指定 activemq 配置文件 url 的位置(注意:我无法使用相对路径(如 conf/activemq.xml)。所以,我最终使用了绝对路径)
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->

  <!-- activate next line to be able to deploy applications in apps -->
  <!-- <Deployments dir="apps" /> -->
  

    <Resource id="BossJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig =  xbean:file:/var/apps/apache-tomee-plus-9.0/boss/usmo/Boss/resources/properties/activemq.xml
        ServerUrl       =  vm://localhost
    </Resource>

    <Resource id="BossJmsConnectionFactory" type="jakarta.jms.ConnectionFactory">
        ResourceAdapter = BossJmsResourceAdapter
    </Resource>

    <Container id="BossJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter = BossJmsResourceAdapter
    </Container>

    <Resource id="jms/TransactionManager" type="jakarta.jms.Queue"/>
    <Resource id="jms/EmailManager" type="jakarta.jms.Queue"/>

</tomee>
  1. 在步骤 2 中指定的 url 处创建一个 activemq.xml 文件。下面是一个示例:
<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-5.8.0.xsd">
<!--  Allows us to use external properties as variables in this configuration file  -->
    <broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" brokerName="localhost" useShutdownHook="false" persistent="true" start="false" schedulerSupport="false" enableStatistics="false" offlineDurableSubscriberTimeout="259200000" offlineDurableSubscriberTaskSchedule="3600000">
        <persistenceAdapter>
            <kahaDB directory="/var/apps/apache-tomee-plus-9.0/boss/usmo/Boss/resources/jmsQueues/activemq-data/kaha" indexCacheSize="20000" ignoreMissingJournalfiles="true" checkForCorruptJournalFiles="true" checksumJournalFiles="true"/>
        </persistenceAdapter>
        <!--  The transport connectors ActiveMQ will listen to. Set the same for the serverUrl in the tomee.xml file  -->
        <transportConnectors>
            <!-- Local broker -->
            <transportConnector name="vm" uri="vm://localhost"/>
        </transportConnectors>
    </broker>
</beans>

0
投票

是什么阻止您将此 activemq/activmq-data 目录移动到非 system32 位置?

参考:https://activemq.apache.org/version-5-getting-started.html

以 zip 格式下载并使其在方便的位置运行。

© www.soinside.com 2019 - 2024. All rights reserved.