This commit is contained in:
Clebert Suconic 2017-08-07 18:47:34 -04:00
commit 2fc4eb3353
12 changed files with 62 additions and 46 deletions

View File

@ -46,6 +46,10 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
@ -111,9 +115,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-Djava.util.logging.config.file=${project.build.directory}/../../../distribution/activemq/src/main/resources/config/stand-alone/non-clustered/logging.properties
</argLine>
<argLine>${activemq-surefire-argline}</argLine>
<skipTests>${skipRestTests}</skipTests>
<!--includes>
<include>**/PushQueueConsumerTest.java</include>

View File

@ -72,6 +72,10 @@ public interface ActiveMQRestLogger extends BasicLogger {
@Message(id = 182003, value = "Failed to build Message from object", format = Message.Format.MESSAGE_FORMAT)
void failedToBuildMessageFromObject(@Cause Exception e);
@LogMessage(level = Logger.Level.WARN)
@Message(id = 182004, value = "REST configuration parameter ''{0}'' is deprecated. Use ''{1}'' instead.", format = Message.Format.MESSAGE_FORMAT)
void deprecatedConfiguration(String oldConfigParameter, String newConfigParameter);
@LogMessage(level = Logger.Level.ERROR)
@Message(id = 184000, value = "Failed to load push store {0}, it is probably corrupted", format = Message.Format.MESSAGE_FORMAT)
void errorLoadingStore(@Cause Exception e, String name);

View File

@ -26,12 +26,15 @@ public class MessageServiceConfiguration {
private long producerTimeToLive = -1;
private int timeoutTaskInterval = 1;
private int consumerSessionTimeoutSeconds = 300;
@Deprecated
private int consumerWindowSize = -1;
private boolean defaultDurableSend = false;
private boolean dupsOk = true;
private String topicPushStoreDirectory = "topic-push-store";
private String queuePushStoreDirectory = "queue-push-store";
@Deprecated
private String inVmId = "0";
private String url = "vm://0";
private boolean useLinkHeaders = false;
private String deserializationWhiteList;
@ -43,6 +46,7 @@ public class MessageServiceConfiguration {
}
public void setInVmId(String inVmId) {
ActiveMQRestLogger.LOGGER.deprecatedConfiguration("server-in-vm-id", "url");
this.inVmId = inVmId;
}
@ -133,9 +137,19 @@ public class MessageServiceConfiguration {
}
public void setConsumerWindowSize(int consumerWindowSize) {
ActiveMQRestLogger.LOGGER.deprecatedConfiguration("consumer-window-size", "url");
this.consumerWindowSize = consumerWindowSize;
}
@XmlElement(name = "url")
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDeserializationWhiteList() {
return deserializationWhiteList;
}

View File

@ -21,17 +21,13 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants;
import org.apache.activemq.artemis.jms.client.ConnectionFactoryOptions;
import org.apache.activemq.artemis.rest.queue.DestinationSettings;
import org.apache.activemq.artemis.rest.queue.QueueServiceManager;
@ -143,20 +139,18 @@ public class MessageServiceManager {
defaultSettings.setDuplicatesAllowed(configuration.isDupsOk());
defaultSettings.setDurableSend(configuration.isDefaultDurableSend());
HashMap<String, Object> transportConfig = new HashMap<>();
transportConfig.put(TransportConstants.SERVER_ID_PROP_NAME, configuration.getInVmId());
ServerLocator consumerLocator = new ServerLocatorImpl(false, new TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
ActiveMQRestLogger.LOGGER.debug("Created ServerLocator: " + consumerLocator);
ServerLocator consumerLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
if (configuration.getConsumerWindowSize() != -1) {
consumerLocator.setConsumerWindowSize(configuration.getConsumerWindowSize());
}
ActiveMQRestLogger.LOGGER.debug("Created ServerLocator: " + consumerLocator);
consumerSessionFactory = consumerLocator.createSessionFactory();
ActiveMQRestLogger.LOGGER.debug("Created ClientSessionFactory: " + consumerSessionFactory);
ServerLocator defaultLocator = new ServerLocatorImpl(false, new TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
ServerLocator defaultLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
ClientSessionFactory sessionFactory = defaultLocator.createSessionFactory();

View File

@ -24,7 +24,7 @@ As you can see, we're just posting some arbitrary XML document to a URL.
When the XML is received on the server is it processed within Apache ActiveMQ Artemis
as a JMS message and distributed through core Apache ActiveMQ Artemis. Simple and easy.
Consuming messages from a queue or topic looks very similar. We'll
discuss the entire interface in detail later in this docbook.
discuss the entire interface in detail later.
## Goals of REST Interface
@ -57,11 +57,11 @@ of the REST interface?
## Installation and Configuration
Apache ActiveMQ Artemis's REST interface is installed as a Web archive (WAR). It depends on the [RESTEasy](http://jboss.org/resteasy) project and can currently only run within a servlet container. Installing the Apache ActiveMQ Artemis REST interface is a little bit different depending whether Apache ActiveMQ Artemis is already installed and configured for your environment (e.g. you're deploying within Wildfly) or you want the ActiveMQ Artemis REST WAR to startup and manage the Apache ActiveMQ Artemis server (e.g. you're deploying within something like Apache Tomcat).
Apache ActiveMQ Artemis's REST interface is installed as a Web archive (WAR). It depends on the [RESTEasy](http://jboss.org/resteasy) project and can currently only run within a servlet container. Installing the Apache ActiveMQ Artemis REST interface is a little bit different depending whether Apache ActiveMQ Artemis is already embedded (e.g. you're deploying within Wildfly) or configured on the network somewhere, or you want the ActiveMQ Artemis REST WAR itself to startup and manage the Apache ActiveMQ Artemis server.
### Installing Within Pre-configured Environment
This section should be used when you want to use the Apache ActiveMQ Artemis REST interface in an environment that already has Apache ActiveMQ Artemis installed and running, e.g. the Wildfly application server. You must create a Web archive (.WAR) file with the following web.xml settings:
This section should be used when you want to use the Apache ActiveMQ Artemis REST interface in an environment that already has Apache ActiveMQ Artemis installed and running. You must create a Web archive (.WAR) file with the following web.xml settings:
<web-app>
<listener>
@ -89,7 +89,7 @@ This section should be used when you want to use the Apache ActiveMQ Artemis RES
</filter-mapping>
</web-app>
Within your WEB-INF/lib directory you must have the Apache ActiveMQ Artemis-rest.jar file. If RESTEasy is not installed within your environment, you must add the RESTEasy jar files within the lib directory as well. Here's a sample Maven pom.xml that can build a WAR with the Apache ActiveMQ Artemis REST library.
Within your WEB-INF/lib directory you must have the artemis-rest.jar file. If RESTEasy is not installed within your environment, you must add the RESTEasy jar files within the lib directory as well. Here's a sample Maven pom.xml that can build a WAR with the Apache ActiveMQ Artemis REST library.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@ -131,7 +131,7 @@ It is worth noting that when deploying a WAR in a Java EE application server lik
### Bootstrapping ActiveMQ Artemis Along with REST
You can bootstrap Apache ActiveMQ Artemis within your WAR as well. To do this, you must have the Apache ActiveMQ Artemis core and JMS jars along with Netty, RESTEasy, and the Apache ActiveMQ Artemis REST jar within your WEB-INF/lib. You must also have an Apache ActiveMQ Artemis-configuration.xml config file within WEB-INF/classes. The examples that come with the Apache ActiveMQ Artemis REST distribution show how to do this. You must also add an additional listener to your web.xml file. Here's an example:
You can bootstrap Apache ActiveMQ Artemis within your WAR as well. To do this, you must have the Apache ActiveMQ Artemis core and JMS jars along with Netty, RESTEasy, and the Apache ActiveMQ Artemis REST jar within your WEB-INF/lib. You must also have a broker.xml config file within WEB-INF/classes. The examples that come with the Apache ActiveMQ Artemis REST distribution show how to do this. You must also add an additional listener to your web.xml file. Here's an example:
<web-app>
<listener>
@ -208,7 +208,7 @@ file. Below is the format of the XML configuration file and the default
values for each.
<rest-messaging>
<server-in-vm-id>0</server-in-vm-id>
<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>
@ -218,14 +218,17 @@ values for each.
<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>
<consumer-window-size>-1</consumer-window-size> <!-- deprecated, use "url" -->
<url>vm://0</url>
</rest-messaging>
Let's give an explanation of each config option.
- `server-in-vm-id`. The Apache ActiveMQ Artemis REST impl uses the IN-VM transport
to communicate with Apache ActiveMQ Artemis. It uses the default server id, which
is "0".
- `server-in-vm-id`. The Apache ActiveMQ Artemis REST implementation was formerly hard-coded
to use the in-vm transport to communicate with the embedded Apache ActiveMQ Artemis instance.
This is the id of the embedded instance. It is "0" by default. Note: this is deprecated in
favor of `url` which can be used to connect to an arbitrary instance of Apache ActiveMQ
Artemis (including one over the network).
- `use-link-headers`. By default, all links (URLs) are published using
custom headers. You can instead have the Apache ActiveMQ Artemis REST
@ -265,13 +268,18 @@ Let's give an explanation of each config option.
- `consumer-window-size`. For consumers, this config option is the
same as the Apache ActiveMQ Artemis one of the same name. It will be used by
sessions created by the Apache ActiveMQ Artemis REST implementation.
This is deprecated in favor of `url` as it can be specified as a URL
parameter.
- `url`. The URL the Apache ActiveMQ Artemis REST implementation should use
to connect to the Apache ActiveMQ Artemis instance. Default to "vm://0".
## Apache ActiveMQ Artemis REST Interface Basics
The Apache ActiveMQ Artemis REST interface publishes a variety of REST resources to
perform various tasks on a queue or topic. Only the top-level queue and
topic URI schemes are published to the outside world. You must discover
all over resources to interact with by looking for and traversing links.
all other resources to interact with by looking for and traversing links.
You'll find published links within custom response headers and embedded
in published XML representations. Let's look at how this works.
@ -287,12 +295,8 @@ The base of the URI is the base URL of the WAR you deployed the Apache ActiveMQ
REST server within as defined in the [Installation and
Configuration](#install) section of this document. Replace the `{name}`
string within the above URI pattern with the name of the queue or topic
you are interested in interacting with. For example if you have
configured a named "foo" within your `activemq-jms.xml` file,
the URI name should be "foo". If you have configured a JMS
queue name "bar" within your `activemq-jms.xml` file, the URI name
should be "bar". Next, perform your HEAD or GET request on this URI.
Here's what a request/response would look like.
you are interested in interacting with. Next, perform your HEAD or GET
request on this URI. Here's what a request/response would look like.
HEAD /queues/bar HTTP/1.1
Host: example.com
@ -309,7 +313,7 @@ Here's what a request/response would look like.
> You can use the "curl" utility to test this easily. Simply execute a
> command like this:
>
> curl --head http://example.com/queues/.bar
> curl --head http://example.com/queues/bar
The HEAD or GET response contains a number of custom response headers
that are URLs to additional REST resources that allow you to interact
@ -1010,7 +1014,7 @@ resource.
acknowledge=true
--- Response ---
Http/1.1 200 Ok
Http/1.1 204 Ok
msg-acknowledge-next:
http://example.com/queues/bar/pull-consumers/333/acknowledge-next-2
@ -1338,9 +1342,7 @@ headers might look like:
You can create a durable queue or topic through the REST interface.
Currently you cannot create a temporary queue or topic. To create a
queue you do a POST to the relative URL /queues with an XML
representation of the queue. The XML syntax is the same queue syntax
that you would specify in activemq-jms.xml if you were creating a queue
there. For example:
representation of the queue. For example:
POST /queues
Host: example.com

View File

@ -27,10 +27,10 @@ under the License.
<acceptors>
<acceptor name="in-vm">vm://0</acceptor>
</acceptors>
<addresses>
<addresses>
<address name="orders">
<anycast>
<queue name="jms.queue.orders"/>
<queue name="orders"/>
</anycast>
</address>
</addresses>

View File

@ -27,7 +27,7 @@ under the License.
<acceptors>
<acceptor name="in-vm">vm://0</acceptor>
</acceptors>
<addresses>
<addresses>
<address name="chat">
<multicast/>
</address>

View File

@ -148,7 +148,7 @@ under the License.
}
}
initializeSenderAndTop('jms.topic.chat');
initializeSenderAndTop('chat');
setTimeout("receiveMessage()", 800);

View File

@ -17,7 +17,7 @@
import httplib, urlparse
conn = httplib.HTTPConnection("localhost:8080")
conn.request("HEAD", "/queues/jms.queue.orders")
conn.request("HEAD", "/queues/orders")
res = conn.getresponse()
createLink = res.getheader("msg-create")
print createLink

View File

@ -17,7 +17,7 @@
import httplib, urlparse
conn = httplib.HTTPConnection("localhost:8080")
conn.request("HEAD", "/queues/jms.queue.orders")
conn.request("HEAD", "/queues/orders")
res = conn.getresponse()
consumersLink = res.getheader("msg-pull-consumers")
consumersParsed = urlparse.urlparse(consumersLink)

View File

@ -28,10 +28,10 @@ under the License.
<acceptor name="in-vm">vm://0</acceptor>
<acceptor name="netty">tcp://localhost:61616</acceptor>
</acceptors>
<addresses>
<addresses>
<address name="orders">
<anycast>
<queue name="jms.queue.orders"/>
<queue name="orders"/>
</anycast>
</address>
</addresses>

View File

@ -31,12 +31,12 @@ under the License.
<addresses>
<address name="shipping">
<anycast>
<queue name="jms.queue.shipping"/>
<queue name="shipping"/>
</anycast>
</address>
<address name="orders">
<anycast>
<queue name="jms.queue.orders"/>
<queue name="orders"/>
</anycast>
</address>
</addresses>