ActiveMQ Artemis REST 接口配置

3
我试图将ActiveMQ Artemis的REST接口添加到我的Docker容器中,为此我一直在遵循官方指南official guide。我生成了一个artemis-rest.war文件,并将其移动到/opt/artemis/web文件夹中。现在,当我导航到http://localhost:8161/artemis-rest/queues/queue_name时,我得到了404错误。当我尝试导航到/opt/artemis/web中列出的其他资源,如/console/或/artemis-plugin/时,我至少会得到某种响应。
我的文件夹结构如下:
|-- pom.xml
`-- src
   `-- main
       `-- webapp
           `-- WEB-INF
               `-- web.xml
       `-- resources
           `-- rest.xml

pom.xml:

<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.somebody</groupId>
    <artifactId>artemis-rest</artifactId>
    <packaging>war</packaging>
    <name>ActiveMQ Artemis REST</name>
    <version>2.17.0</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.activemq.rest</groupId>
            <artifactId>artemis-rest</artifactId>
            <version>2.17.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.activemq</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.jetty.aggregate</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.logging</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.logmanager</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>

rest.xml:

<rest-messaging>
    <server-in-vm-id>0</server-in-vm-id> <!-- deprecated, use "url" -->
    <use-link-headers>false</use-link-headers>
    <default-durable-send>false</default-durable-send>
    <dups-ok>true</dups-ok>
    <topic-push-store-dir>topic-push-store</topic-push-store-dir>
    <queue-push-store-dir>queue-push-store</queue-push-store-dir>
    <producer-time-to-live>0</producer-time-to-live>
    <producer-session-pool-size>10</producer-session-pool-size>
    <session-timeout-task-interval>1</session-timeout-task-interval>
    <consumer-session-timeout-seconds>300</consumer-session-timeout-seconds>
    <consumer-window-size>-1</consumer-window-size> <!-- deprecated, use "url" -->
    <url>vm://0</url>
</rest-messaging>

web.xml:

<web-app>
    <listener>
        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    </listener>
    
    <listener>
        <listener-class>org.apache.activemq.artemis.rest.integration.RestMessagingBootstrapListener</listener-class>
    </listener>
    
    <filter>
        <filter-name>Rest-Messaging</filter-name>
        <filter-class>org.jboss.resteasy.plugins.server.servlet.FilterDispatcher</filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>Rest-Messaging</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <context-param>
        <param-name>rest.messaging.config.file</param-name>
        <param-value>rest.xml</param-value>
    </context-param>
</web-app>

我错过了什么吗?还需要配置什么吗? 我本以为包含.war文件就足够了,至少可以得到某种错误。


出于好奇,你为什么要使用REST接口?一般来说,我建议不要使用ActiveMQ Artemis REST接口,原因有两个。1)由于ActiveMQ Artemis REST接口是自定义(即非标准化)接口,因此您的代码将无法移植。2)STOMP协议是普遍存在、简单、标准化的,并且可以在几乎所有可能使用REST的情况和环境中使用。如果可能的话,我建议您使用STOMP代替ActiveMQ Artemis REST接口。 - Justin Bertram
@JustinBertram 很抱歉等待这么久,我们计划将其用于集成测试。 - maun
你能帮我理解为什么要在集成测试中使用它,而不是像STOMP这样的其他东西吗? - Justin Bertram
我们选择REST是因为它是大多数人熟悉的消息传递协议。 - maun
1
问题在于REST 不是消息协议。实际上,它根本不是协议,只是一种架构风格。它使用HTTP作为协议,而HTTP也不是消息协议。这就是我在第一条评论中描述的问题。由于REST不是消息协议,因此您的客户端将不得不使用ActiveMQ Artemis在REST之上构建的消息协议,这将使您的应用程序不可移植。我建议您转移到像STOMP这样的标准化协议。 - Justin Bertram
1个回答

1
您需要在 etc/bootstrap.xml 中部署 artemis-rest.war,例如:
   <web bind="http://localhost:8161" path="web">
       ...
       <app url="artemis-rest" war="artemis-rest.war"/>
   </web>

嵌入式Web服务器不会自动部署artemis-rest.war,即使您将其放入web目录中。请注意,此操作需要手动完成。

谢谢!我知道我漏掉了什么。 - maun

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接