ActiveMQ Artemis 和代理 URI

ActiveMQ Artemis and broker URI

我有一个 Spring 框架配置文件

<?xml version="1.0" encoding="UTF-8"?>
<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.15.12.xsd">

    <amq:queue id="testRequestQueue" physicalName="test.storm.in.request.queue" />

    <amq:connectionFactory id="jmsConnectionFactory" brokerURL="failover:(tcp://localhost:61616)?retryInterval=1000&amp;retryIntervalMultiplier=1.5&amp;maxRetryInterval=60000&amp;maxReconnectAttempts=1000" />

</beans>

但是,当我 运行 在 Storm 集群上时,我收到一条错误消息:

Caused by: java.lang.IllegalArgumentException: Invalid connect parameters: {retryIntervalMultiplier=1.5, maxRetryInterval=60000, retryInterval=1000}

文档非常混乱。我不确定 ActiveMQ 和 ActiveMQ Artemis 配置是否相同或相似。我不知道如何为 Apache ActiveMQ Artemis 配置代理 uri。

所以我的问题是我做错了什么?

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>itvs_pletra_imaps_test1_pagal_schema</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.plugin>3.8.1</maven.compiler.plugin>
        <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
        <maven-war-plugin.version>3.3.1</maven-war-plugin.version>
        <javee-api.version>8.0.1</javee-api.version>
        <reactive-streams.version>1.0.3</reactive-streams.version>
        <spring-web-and-context.version>5.2.9.RELEASE</spring-web-and-context.version>
        <httpclient.version>4.5.12</httpclient.version>
        <jaxb-api.version>2.4.0-b180830.0359</jaxb-api.version>
        <hibernate-core.version>5.3.0.Final</hibernate-core.version>
        <mockito-junit-jupiter.version>3.5.10</mockito-junit-jupiter.version>
        <junit-jupiter-api.version>5.7.0</junit-jupiter-api.version>
        <junit-jupiter-params.version>5.7.0</junit-jupiter-params.version>
        <slf4j-api.version>2.0.0-alpha1</slf4j-api.version>
        <log4j-core.version>2.13.3</log4j-core.version>
        <log4j-slf4j-impl.version>2.13.3</log4j-slf4j-impl.version>
        <cxf-rt-frontend-jaxws.version>3.3.6</cxf-rt-frontend-jaxws.version>
        <cxf.version>3.4.0</cxf.version>
        <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
        <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
        <storm-core.version>2.2.0</storm-core.version>
        <storm-client.version>2.2.0</storm-client.version>
        <storm-jms.version>2.2.0</storm-jms.version>
        <activemq-spring.version>5.16.0</activemq-spring.version>
        <javax.jms-api.version>2.0.1</javax.jms-api.version>
        <artemis-spring-integration.version>2.15.0</artemis-spring-integration.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>${jaxb-api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-jms-examples</artifactId>
            <version>${storm-core.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.jms</groupId>
            <artifactId>javax.jms-api</artifactId>
            <version>${javax.jms-api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>apache-artemis</artifactId>
            <version>2.15.0</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring-web-and-context.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-spring</artifactId>
            <version>${activemq-spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-spring-integration</artifactId>
            <version>2.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xbean</groupId>
            <artifactId>xbean-spring</artifactId>
            <version>4.18</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf-rt-frontend-jaxws.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-core</artifactId>
            <version>${storm-core.version}</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-jms</artifactId>
            <version>${storm-jms.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-client</artifactId>
            <version>${storm-client.version}</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <!-- declare the exclusion here -->
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                </exclusion>
                <exclusion>
                    <!-- declare the exclusion here -->
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <!-- declare the exclusion here -->
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <!-- declare the exclusion here -->
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>
                <exclusion>
                    <!-- declare the exclusion here -->
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.reactivestreams</groupId>
            <artifactId>reactive-streams</artifactId>
            <version>${reactive-streams.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j-api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpclient.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j-core.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>${log4j-slf4j-impl.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.ws</groupId>
            <artifactId>jbossws-api</artifactId>
            <version>1.1.2.Final</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>${javee-api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate-core.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${junit-jupiter-params.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit-jupiter-api.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>${mockito-junit-jupiter.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

URI 100% 取决于您使用的客户端。 ActiveMQ 5.x JMS 客户端实现不同于 ActiveMQ Artemis JMS 客户端实现。事实上,他们在幕后使用完全不同的协议(即 5.x 的 OpenWire 和 Artemis 的“核心”)。

从您的 Spring 配置中看不出您使用的是哪个客户端。此外,由于您已经定义了 both 5.x 和 Artemis 依赖项,因此从您的 pom.xml 中不清楚您正在使用哪个客户端,例如:

...
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>apache-artemis</artifactId>
    <version>2.15.0</version>
    <type>pom</type>
</dependency>
...
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-spring</artifactId>
    <version>${activemq-spring.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>artemis-spring-integration</artifactId>
    <version>2.15.0</version>
</dependency>
...

但是,您收到的异常消息(即“无效的连接参数”)表明您正在使用 ActiveMQ 5.x OpenWire JMS 客户端。不幸的是,您使用的参数适用于 ActiveMQ Artemis JMS 客户端(即 retryIntervalMultiplier=1.5, maxRetryInterval=60000, retryInterval=1000)。

因此,您要么需要更改项目以便使用 ActiveMQ Artemis JMS 客户端,要么删除那些不正确的参数。

明确地说,ActiveMQ Artemis 用户手册中记录的客户端 URL 参数专门用于 ActiveMQ Artemis JMS 或核心客户端。您可以找到 ActiveMQ 5.x 客户端 here.

的参数

如果您想在 Spring 配置中使用 ActiveMQ Artemis 资源,您可以使用如下内容:

<bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory">
   <property name="brokerURL" value="tcp://localhost:61616?ha=true&amp;retryInterval=1000&amp;retryIntervalMultiplier=1.5&amp;maxRetryInterval=60000&amp;maxReconnectAttempts=1000"/>
</bean>

<bean id="testRequestQueue" class="org.apache.activemq.artemis.jms.client.ActiveMQQueue">
   <constructor-arg index="0" value="test.storm.in.request.queue"/>
</bean>

之后,您可以从 pom.xml 中删除任何 ActiveMQ 5.x 依赖项,并从 Spring 配置中删除 xmlns:amq="activemq.apache.org/schema/core"