简体   繁体   中英

How to enable REST in an ActiveMQ Artemis cluster

We are trying to setup a REST interface as stated in the ActiveMQ Artemis documentation . We have got it to work in versions 2.10.1 and 2.9.0, but only in standalone mode. A clustered 2.9.0 is our current production environment and that is where we are trying to setup the REST interface.

We have a clustered active/passive solution using the file-based journal. We have a Netscaler in front of our active/passive solution. We found this bug report which is what we see in our system. This bug is solved in 2.3.0, so I guess we should run TCP instead of in-vm? How do we set that up?

Config for our working 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>

In broker.xml we added:

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

In rest-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>

In 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>

This works fine (when including below 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());
    }
}

How can I get this working in a clustered environment? How can we use TCP instead of in-vm?

If you want to use TCP for REST you simply need to configure it in your rest-messaging.xml , eg:

<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>

If you want to use REST with a master/slave HA pair then you should configure a web application server (eg Tomcat or Jetty) on a separate machine "in front" of the master & slave brokers and use a URL like this:

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

That said, I would not recommend using REST because while REST is relatively simple there is no standard REST interface for messaging so your REST clients will be tied to ActiveMQ Artemis (which is not good for application portability). Typically STOMP is a good replacement for REST. STOMP is a simple, text-based protocol which can be used from JavaScript and most of the the same places which REST can be used plus its standardized so you'll find lots of client implementations in lots of different languages.

Furthermore, security is not currently implemented for the connection between the REST interface and the remote brokers which means any client could potentially connect to the brokers and consume or produce messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM