我们正在尝试按照ActiveMQ Artemis文档中的说明设置REST接口。我们已经使其可以在2.10.1和2.9.0版本中工作,但只能在独立模式下使用。集群2.9.0是我们当前的生产环境,因此我们正在尝试设置REST接口。
我们有一个使用基于文件的日志的群集主动/被动解决方案。我们的主动/被动解决方案前面有一个Netscaler。我们发现了这个错误报告,这是我们在系统中看到的。此错误已在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>
在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>
在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>
这可以正常工作(包括下面的类时):
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?
如果要将TCP用于REST,则只需在中配置它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>
如果要对主/从HA对使用REST,则应在主代理和从代理“前面”的另一台机器上配置Web应用程序服务器(例如Tomcat或Jetty),并使用如下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接口与远程代理之间的连接实现安全性,这意味着任何客户端都可能潜在地连接到代理并使用或产生消息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句