Artemis 集群抛出 ClassNotFoundException:org.hornetq.core.remoting.impl.netty.NettyConnectorFactory

Artemis cluster throws ClassNotFoundException: org.hornetq.core.remoting.impl.netty.NettyConnectorFactory

我准备了 java 带有嵌入式 Artemis 代理的应用程序。它是包含所有依赖项的单个 jar。 我使用 org.apache.activemq:artemis-server:2.10.1 并按以下方式启动代理:

new EmbeddedActiveMQ().setConfigResourcePath( config ).start();

其中 config 是一个 URL 配置文件。 我使用一个配置文件作为主设备,一个配置文件作为从设备。

师傅:

<!--
  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.
-->
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">

    <core xmlns="urn:activemq:core">

        <persistence-enabled>true</persistence-enabled>
        <security-enabled>false</security-enabled>
        <acceptors>
            <acceptor name="netty-acceptor">tcp://127.0.0.1:61617</acceptor>
        </acceptors>
        <bindings-directory>artemis/bindings</bindings-directory>
        <journal-directory>artemis/journal</journal-directory>
        <address-settings>
            <address-setting match="#">
                <dead-letter-address>DLQ</dead-letter-address>
            </address-setting>
        </address-settings>
        <addresses>
            <address name="DLQ">
                <anycast>
                    <queue name="DLQ"/>
                </anycast>
            </address>
        </addresses>

        <connectors>
            <!-- Connector used to be announced through cluster connections and notifications -->
            <connector name="artemis">tcp://127.0.0.1:61617</connector>
        </connectors>
        <cluster-user>artemis-cluster</cluster-user>
        <cluster-password>artemis-cluster</cluster-password>


        <broadcast-groups>
            <broadcast-group name="bg-group1">
                <group-address>231.7.7.7</group-address>
                <group-port>9876</group-port>
                <broadcast-period>5000</broadcast-period>
                <connector-ref>artemis</connector-ref>
            </broadcast-group>
        </broadcast-groups>

        <discovery-groups>
            <discovery-group name="dg-group1">
                <group-address>231.7.7.7</group-address>
                <group-port>9876</group-port>
                <refresh-timeout>10000</refresh-timeout>
            </discovery-group>
        </discovery-groups>

        <cluster-connections>
            <cluster-connection name="my-cluster">
                <address></address>
                <connector-ref>artemis</connector-ref>
                <message-load-balancing>ON_DEMAND</message-load-balancing>
                <max-hops>1</max-hops>
                <discovery-group-ref discovery-group-name="dg-group1"/>
            </cluster-connection>
        </cluster-connections>
        <ha-policy>
            <replication>
                <master/>
            </replication>
        </ha-policy>
    </core>

</configuration>

从机:

<core xmlns="urn:activemq:core">

    <persistence-enabled>true</persistence-enabled>
    <security-enabled>false</security-enabled>
    <acceptors>
        <acceptor name="netty-acceptor">tcp://127.0.0.1:61618</acceptor>
    </acceptors>
    <bindings-directory>artemis/bindings</bindings-directory>
    <journal-directory>artemis/journal</journal-directory>
    <address-settings>
        <address-setting match="#">
            <dead-letter-address>DLQ</dead-letter-address>
        </address-setting>
    </address-settings>
    <addresses>
        <address name="DLQ">
            <anycast>
                <queue name="DLQ"/>
            </anycast>
        </address>
    </addresses>

    <connectors>
        <!-- Connector used to be announced through cluster connections and notifications -->
        <connector name="artemis">tcp://127.0.0.1:61618</connector>
    </connectors>
    <cluster-user>artemis-cluster</cluster-user>
    <cluster-password>artemis-cluster</cluster-password>

    <broadcast-groups>
        <broadcast-group name="bg-group1">
            <group-address>231.7.7.7</group-address>
            <group-port>9876</group-port>
            <broadcast-period>5000</broadcast-period>
            <connector-ref>artemis</connector-ref>
        </broadcast-group>
    </broadcast-groups>

    <discovery-groups>
        <discovery-group name="dg-group1">
            <group-address>231.7.7.7</group-address>
            <group-port>9876</group-port>
            <refresh-timeout>10000</refresh-timeout>
        </discovery-group>
    </discovery-groups>

    <cluster-connections>
        <cluster-connection name="my-cluster">
            <address></address>
            <connector-ref>artemis</connector-ref>
            <message-load-balancing>ON_DEMAND</message-load-balancing>
            <max-hops>1</max-hops>
            <discovery-group-ref discovery-group-name="dg-group1"/>
        </cluster-connection>
    </cluster-connections>
    <ha-policy>
        <replication>
            <slave/>
        </replication>
    </ha-policy>


</core>

在Windows 10 和Centos 7 上正常工作。在Oracle Linux 7 上不工作。所有机器都使用相同的Java 版本。

java -version
openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+11, mixed mode)

Windows 和 Centos 上没有任何异常,我看到以下日志:

11:14:30.867 [Thread-0] INFO  org.apache.activemq.artemis.core.server - AMQ221025: Replication: sending NIOSequentialFile...

11:14:33.911 [Thread-1 (ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl@2a3c96e3)] INFO  org.apache.activemq.artemis.core.server - AMQ221031: backup announced

完全相同的 jar 和完全相同的配置文件在 Oracle 上抛出异常 Linux:

11:31:56.074 [Thread-0 (ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl@63b1d4fa)] WARN  org.apache.activemq.artemis.core.client - AMQ212025: did not connect the cluster connection to other nodes
java.lang.IllegalStateException: java.lang.ClassNotFoundException: org.hornetq.core.remoting.impl.netty.NettyConnectorFactory
        at org.apache.activemq.artemis.utils.ClassloadingUtil.newInstanceFromClassLoader(ClassloadingUtil.java:59) ~[broker.jar:?]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.run(ClientSessionFactoryImpl.java:996) ~[broker.jar:?]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.run(ClientSessionFactoryImpl.java:993) ~[broker.jar:?]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.instantiateConnectorFactory(ClientSessionFactoryImpl.java:993) ~[broker.jar:?]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.<init>(ClientSessionFactoryImpl.java:181) ~[broker.jar:?]
        at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:798) ~[broker.jar:?]
        at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.connect(ServerLocatorImpl.java:655) ~[broker.jar:?]
        at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.connect(ServerLocatorImpl.java:637) ~[broker.jar:?]
        at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.run(ServerLocatorImpl.java:595) ~[broker.jar:?]
        at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:42) ~[broker.jar:?]
        at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:31) ~[broker.jar:?]
        at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:66) ~[broker.jar:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at org.apache.activemq.artemis.utils.ActiveMQThreadFactory.run(ActiveMQThreadFactory.java:118) [broker.jar:?]
Caused by: java.lang.ClassNotFoundException: org.hornetq.core.remoting.impl.netty.NettyConnectorFactory
        at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[?:?]
        at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[?:?]
        at org.apache.activemq.artemis.utils.ClassloadingUtil.newInstanceFromClassLoader(ClassloadingUtil.java:55) ~[broker.jar:?]
        ... 15 more

主从都抛出相同的异常。为什么 Artemis 要在 Oracle Linux 上使用 org.hornetq.core.remoting.impl.netty.NettyConnectorFactory?我在 Windows 上调试了我的应用程序,那里使用了 org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory。哪里可以配置?也许在用户目录中有一些配置文件或类似的东西?也许我可以通过将 hornetq 添加到依赖项来解决这个问题,但我更喜欢使用 Artemis 的 NettyConnectorFactory。我不明白为什么一台机器使用与其他两台机器不同的 NettyConnectorFactory。

这几乎可以肯定是由您网络上的 HornetQ 代理造成的,该代理使用相同的 group-addressgroup-port(即 231.7.7.7:9876)来广播其连接器信息。您使用的是默认值,所以这并不奇怪。您应该找到这个 HornetQ 代理并停止它,或者更改您的 Artemis 集群配置以使用不同的 group-address and/or group-port.