如何在 ActiveMQ Artemis 集群中启用 REST

How to enable REST in an ActiveMQ Artemis cluster

我们正在尝试设置 the ActiveMQ Artemis documentation 中所述的 REST 界面。我们已经让它在 2.10.1 和 2.9.0 版本中工作,但只能在独立模式下工作。集群 2.9.0 是我们当前的生产环境,也是我们尝试设置 REST 接口的地方。

我们有一个使用基于文件的日志的集群 active/passive 解决方案。我们的 active/passive 解决方案前面有一个 Netscaler。我们发现 this bug report 这就是我们在系统中看到的。这个错误在 2.3.0 中解决了,所以我想我们应该 运行 TCP 而不是 in-vm?我们如何设置它?

我们工作的 StdAlone 的配置:

<web bind="http://lxappqmanv01:8161" path="web">
   <app url="activemq-branding" war="activemq-branding.war"/>
   <app url="artemis-plugin" war="artemis-plugin.war"/>
   <app url="console" war="console.war"/>
   <app url="rest" war="artemis-rest-1.0-SNAPSHOT.war"/>
</web>

在 broker.xml 中我们添加了:

<acceptor name="in-vm">vm://0</acceptor>

休息中-messaging.xml

<rest-messaging>
   <server-in-vm-id>0</server-in-vm-id>
   <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>
   <url>vm://0</url>
</rest-messaging>

在web.xml

<web-app>
   <listener>
      <listener-class>com.myapp.artemis.MyResteasyBootstrap</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>
</web-app>

这很好用(当包括以下 class 时):

package com.myapp.artemis;

import javax.servlet.ServletContextEvent;
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;
import org.jboss.resteasy.spi.Registry;


public class MyResteasyBootstrap extends ResteasyBootstrap {
    @Override
    public void contextInitialized(ServletContextEvent event)
    {
        super.contextInitialized(event);
        event.getServletContext().setAttribute(Registry.class.getName(), deployment.getRegistry());
    }
}

我怎样才能让它在集群环境中工作?我们如何使用TCP 而不是 in-vm?

如果你想为 REST 使用 TCP,你只需要在你的 rest-messaging.xml 中配置它,例如:

<rest-messaging>
   <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>
   <url>tcp://127.0.0.1:61616</url>
</rest-messaging>

如果您想将 REST 与 master/slave HA 对一起使用,那么您应该在主机 "in front" 的单独机器上配置 Web 应用程序服务器(例如 Tomcat 或 Jetty) & slave brokers 并像这样使用 URL:

<url>(tcp://master:61616,tcp://slave:61616)?ha=true;reconnectAttempts=-1</url>

也就是说,我不建议使用 REST,因为虽然 REST 相对简单,但没有用于消息传递的标准 REST 接口,因此您的 REST 客户端将绑定到 ActiveMQ Artemis(这不利于应用程序的可移植性)。通常 STOMP 是 REST 的一个很好的替代品。 STOMP 是一个简单的、基于文本的协议,可以在 JavaScript 和大多数可以使用 REST 的地方使用,加上它的标准化,所以你会发现许多不同语言的客户端实现。

此外,目前还没有为 REST 接口和远程代理之间的连接实现安全性,这意味着任何客户端都可能连接到代理并使用或生成消息。