jbertram commented on a change in pull request #3930:
URL: https://github.com/apache/activemq-artemis/pull/3930#discussion_r812335923
##########
File path: docs/user-manual/en/address-model.md
##########
@@ -1,455 +1,242 @@
-# Addressing Model
+# Address Model
-Apache ActiveMQ Artemis has a unique addressing model that is both powerful and
-flexible and that offers great performance. The addressing model comprises
-three main concepts: **addresses**, **queues**, and **routing types**.
+Every messaging protocol and API that Apache ActiveMQ Artemis supports defines
+a different set of messaging resources.
+
+ - JMS uses _queues_ and _topics_
+ - STOMP uses generic _destinations_
+ - MQTT uses _topics_
+ - AMQP uses generic _nodes_
+
+In order to deal the the unique semantics and use-cases for each of these the
+broker has a flexible and powerful address model and a _core_ set of resources:
+
+ - **address**
+ - **queue**
+ - **routing type**
### Address
-An address represents a messaging endpoint. Within the configuration, a typical
-address is given a unique name, 0 or more queues, and a routing type.
+Messages are *sent* to an address. An address is given a unique name, a routing
+type, and zero or more queues.
### Queue
-A queue is associated with an address. There can be multiple queues per
-address. Once an incoming message is matched to an address, the message will be
-sent on to one or more of its queues, depending on the routing type configured.
-Queues can be configured to be automatically created and deleted.
+Messages are *consumed* from a queue. A queue is bound to an address. There can
+be zero or more queues bound to one address. When a message is sent to an
+address it is routed to one or more of its queues based on the configured
+routing type.
-### Routing Types
+The name of the queue must be _globally_ unique. For example, you can't have a
+queue named `q1` on address `a1` and also a queue named `q1` address `a2`.
-A routing type determines how messages are sent to the queues associated with
-an address. An Apache ActiveMQ Artemis address can be configured with two
-different routing types.
+### Routing Type
-Table 1. Routing Types
+A routing type determines how messages are routed from an address to the
+queue(s) bound to that address. Two different routing types are supported,
+**anycast** and **multicast**.
If you want your messages routed to...|Use this routing type...
---|---
-A single queue within the matching address, in a point-to-point manner.|Anycast
-Every queue within the matching address, in a publish-subscribe
manner.|Multicast
-
-
-**Note:** It is possible to define more than one routing type per address, but
-this typically results in an anti-pattern and is therefore not recommended. If
-an address does use both routing types, however, and the client does not show a
-preference for either one, the broker typically defaults to the anycast routing
-type.
-
-The one exception is when the client uses the MQTT protocol. In that case, the
-default routing type is multicast.
-
-For additional details about these concepts refer to [the core](core.md)
chapter.
-
-## Basic Address Configuration
-
-The following examples show how to configure basic point to point and publish
-subscribe addresses.
-
-### Point-to-Point Messaging
-
-Point-to-point messaging is a common scenario in which a message sent by a
-producer has only one consumer. AMQP and JMS message producers and consumers
-can make use of point-to-point messaging queues, for example. Define an anycast
-routing type for an address so that its queues receive messages in a
-point-to-point manner.
-
-When a message is received on an address using anycast, Apache ActiveMQ Artemis
-locates the queue associated with the address and routes the message to it.
-When consumers request to consume from the address, the broker locates the
-relevant queue and associates this queue with the appropriate consumers. If
-multiple consumers are connected to the same queue, messages are distributed
-amongst each consumer equally, providing the consumers are equally able to
-handle them.
-
-
-Figure 1. Point to Point Messaging
-
-#### Using the Anycast Routing Type
-
-Open the file `<broker-instance>/etc/broker.xml` for editing.
-
-Add an address configuration element and its associated queue if they do not
-exist already.
+a single queue on the address.|anycast
+every queue on the address.|multicast
-**Note:** For normal Point to Point semantics, the queue name **MUST** match
the
-address name.
-
-```xml
-<addresses>
- <address name="orders">
- <anycast>
- <queue name="orders"/>
- </anycast>
- </address>
-</addresses>
-```
+> **Note:**
+>
+> It is possible to define more than one routing type per address, but this
+> typically results in an anti-pattern and is therefore not recommended.
-### Publish-Subscribe Messaging
+## Automatic Configuration
-In a publish-subscribe scenario, messages are sent to every consumer subscribed
-to an address. JMS topics and MQTT subscriptions are two examples of
-publish-subscribe messaging.
+By default Apache ActiveMQ Artemis will automatically create addresses and
+queues to support the semantics of whatever protocol you're using. The broker
+understands how to support each protocol's functionality with the core
+resources so that in most cases no manual configuration is required. This saves
+you from having to preconfigure each address and queue before a client can
+connect to it.
-To configure an address with publish-subscribe semantics, create an address
-with the multicast routing type.
+The broker can optionally be configured to automatically delete addresses and
+queues when they are no longer in use.
-
-Figure 2. Publish-Subscribe
+Automatic creation and deletion is configured on a per address basis and is
+controlled by the following [`address-setting`](address-settings.md) elements:
-#### Using the Multicast Routing Type
+- `auto-create-addresses`
+- `auto-delete-addresses`
+- `default-address-routing-type`
+- `auto-create-queues`
+- `auto-delete-queues`
+- `default-queue-routing-type`
-Open the file `<broker-instance>/etc/broker.xml` for editing.
+See [the documentation on address settings](address-settings.md) for more
+details on these elements.
-Add an address configuration element with multicast routing type.
+Of course, automatic configuration can be disabled and everything can be
+configured manually. Read on for more details about manual configuration.
-```xml
-<addresses>
- <address name="pubsub.foo">
- <multicast/>
- </address>
-</addresses>
-```
+## Basic Manual Configuration
-When clients connect to an address with the multicast element, a subscription
-queue for the client will be automatically created for the client. It is also
-possible to pre-configure subscription queues and connect to them directly
-using the queue's [Fully Qualified Queue names](#fully-qualified-queue-names).
+The following examples show how to configure resources for basic anycast and
+multicast use-cases.
-Optionally add one or more queue elements to the address and wrap the multicast
-element around them. This step is typically not needed since the broker will
-automatically create a queue for each subscription requested by a client.
-
-```xml
-<addresses>
- <address name="pubsub.foo">
- <multicast>
- <queue name="client123.pubsub.foo"/>
- <queue name="client456.pubsub.foo"/>
- </multicast>
- </address>
-</addresses>
-```
-
-Figure 3. Point-to-Point with Two Queues
+> **Note:**
+>
+> Many of the details of these use-cases are protocol agnostic. The goal here
+> is to demonstrate and explain the basic configuration elements and how the
+> address model works fundamentally.
-### Point-to-Point Address multiple Queues
+### Anycast
-It is actually possible to define more than one queue on an address with an
-anycast routing type. When messages are received on such an address, they are
-firstly distributed evenly across all the defined queues. Using [Fully
-Qualified Queue names](#fully-qualified-queue-names), clients are able to
-select the queue that they would like to subscribe to. Should more than one
-consumer connect directly to a single queue, Apache ActiveMQ Artemis will take
-care of distributing messages between them, as in the example above.
+The most common use-case for anycast semantics, sometimes referred to as
+[point-to-point](messaging-concepts.md#point-to-point), involves applications
+following a "competing consumer" pattern to receive messages from a shared
+queue. The more consumers receiving messages the greater the overall message
+throughput. Multiple Java applications sharing a JMS queue is a classic example
+of this use-case.
-
-Figure 3. Point-to-Point with Two Queues
+In this use-case the broker is configured, for example, with an address,
+`anycast.foo` using the `anycast` routing type with just one queue, `q1`. When
+a producer sends a message to `address.foo` it is then routed to `q1` and
+finally dispatched to one of the consumers.
-**Note:** This is how Apache ActiveMQ Artemis handles load balancing of queues
-across multiple nodes in a cluster. Configuring a Point-to-Point Address with
-two queues, open the file `<broker-instance>/etc/broker.xml` for editing.
+
+Figure 1. Anycast
-Add an address configuration with Anycast routing type element and its
-associated queues.
+This is what the configuration for this use-case would look like in
+`etc/broker.xml`:
```xml
<addresses>
<address name="address.foo">
<anycast>
<queue name="q1"/>
- <queue name="q2"/>
</anycast>
</address>
</addresses>
```
-### Point-to-Point and Publish-Subscribe Addresses
-
-It is possible to define an address with both point-to-point and
-publish-subscribe semantics enabled. While not typically recommend, this can be
-useful when you want, for example, a JMS Queue say orders and a JMS Topic named
-orders. The different routing types make the addresses appear to be distinct.
-
-Using an example of JMS Clients, the messages sent by a JMS message producer
-will be routed using the anycast routing type. Messages sent by a JMS topic
-producer will use the multicast routing type. In addition when a JMS topic
-consumer attaches, it will be attached to it’s own subscription queue. JMS
-queue consumer will be attached to the anycast queue.
-
-
-Figure 4. Point-to-Point and Publish-Subscribe
-
-**Note:** The behavior in this scenario is dependent on the protocol being
-used. For JMS there is a clear distinction between topic and queue producers
-and consumers, which make the logic straight forward. Other protocols like AMQP
-do not make this distinction. A message being sent via AMQP will be routed by
-both anycast and multicast and consumers will default to anycast. For more
-information, please check the behavior of each protocol in the sections on
-protocols.
-
-The XML snippet below is an example of what the configuration for an address
-using both anycast and multicast would look like in
-`<broker-instance>/etc/broker.xml`. Note that subscription queues are typically
-created on demand, so there is no need to list specific queue elements inside
-the multicast routing type.
+For most protocols and APIs which support this kind of use-case (e.g. JMS,
+AMQP, etc.) it is customary to use the _same name_ when sending and consuming
+messages. In that case you'd use a configuration like this:
```xml
<addresses>
- <address name="foo.orders">
+ <address name="orderQueue">
<anycast>
- <queue name="orders"/>
+ <queue name="orderQueue"/>
</anycast>
- <multicast/>
</address>
</addresses>
```
-## How to filter messages
+### Multicast
-Apache ActiveMQ Artemis supports the ability to filter messages using Apache
-Artemis [Filter Expressions](filter-expressions.md).
+The most common use-case for multicast semantics, sometimes referred to as
+[publish/subscribe](messaging-concepts.md#publish-subscribe) or "pub/sub",
+involves each application receiving every message sent to an address. Multiple
+applications consuming from a JMS topic is a classic example of this use-case.
+MQTT subscriptions is another supported example of multicast semantics.
-Filters can be applied in two places, on a queue and on a consumer.
+In this use-case the broker is configured with an address, `anycast.foo` using
+the `multicast` routing type with two queues, `q1` & `q2`. When a producer
+sends a message to `address.foo` it is then routed to *both* `q1` & `q2` so
+that ultimately both consumers receive the same messages.
-### Queue Filter
+
+Figure 2. Multicast
-When a filter is applied to a queue, messages are filtered before they are
sent to
-the queue. To add a queue filter use the filter element when configuring a
-queue. Open up `<broker-instance>/etc/broker.xml` and add an address with a
-queue, using the filter element to configure a filter on this queue.
+This is what the configuration for this use-case would look like in
+`etc/broker.xml`:
```xml
<addresses>
- <address name="filter">
- <queue name="filter">
- <filter string="color='red'"/>
- </queue>
+ <address name="address.foo">
+ <multicast>
+ <queue name="q1"/>
+ <queue name="q2"/>
+ </multicast>
</address>
</addresses>
```
-
-The filter defined above ensures that only messages with an attribute
-`"color='red'"` is sent to this queue.
-
-### Consumer Filters
-
-Consumer filters are applied after messages have reached a queue and are
-defined using the appropriate client APIs. The following JMS example shows how
-consumer filters work.
-
-1. Define an address with a single queue, with no filter applied.
+This basic configuration is simple and straight-forward, but there's a
+problem. In a normal pub/sub use-case like with a JMS topic or with MQTT the
+number of subscribers *isn't known ahead of time*. In that case, this is the
+recommended configuration:
```xml
<addresses>
- <address name="filter">
- <queue name="filter"/>
+ <address name="address.foo">
+ <multicast/>
</address>
</addresses>
```
-
-```java
-...
-// Send some messages
-for (int i = 0; i < 3; i ++) {
- TextMessage redMessage = senderSession.createTextMessage("Red");
- redMessage.setStringProperty("color", "red");
- producer.send(redMessage)
-
- TextMessage greenMessage = senderSession.createTextMessage("Green");
- greenMessage.setStringProperty("color", "green");
- producer.send(greenMessage)
-}
-```
-
-At this point the queue would have 6 messages: red,green,red,green,red,green
-
-```java
-MessageConsumer redConsumer = redSession.createConsumer(queue, "color='red'");
-```
-
-The redConsumer has a filter that only matches "red" messages. The redConsumer
-will receive 3 messages.
-
-```
-red, red, red
-```
-
-The resulting queue would now be
-
-```
-green, green, green
-```
-
-## Automatic Address/Queue Management
-
-You can configure Apache ActiveMQ Artemis to automatically create addresses and
-queues, and then delete them when they are no longer in use. This saves you
-from having to preconfigure each address and queue before a client can connect
-to it. Automatic creation and deletion is configured on a per address basis and
-is controlled by following:
-
-Parameter|Description
----|---
-`auto-create-addresses`|When set to true, the broker will create the address
requested by the client if it does not exist already. The default is `true`.
-`auto-delete-addresses`|When set to true, the broker will be delete any
**auto-created** address once all of it’s queues have been deleted. The default
is `true`
-`default-address-routing-type`|The routing type to use if the client does not
specify one. Possible values are `MULTICAST` and `ANYCAST`. See earlier in this
chapter for more information about routing types. The default value is
`MULTICAST`.
-
-### Auto Address Creation
-
-- Edit the file `<broker-instance>/etc/broker.xml` and add the
- `auto-create-addresses` element to the `address-setting` you want the broker
- to automatically create.
-
-- (Optional) Add the `address-setting` if it does not exist. Use the match
- parameter and the [wildcard syntax](wildcard-syntax.md) to match more than
- one specific address.
-
-- Set `auto-create-addresses` to `true`
-
-- (Optional) Assign `MULTICAST` or `ANYCAST` as the default routing type for
- the address.
-
-The example below configures an `address-setting` to be automatically created
-by the broker. The default routing type to be used if not specified by the
-client is MULTICAST. Note that wildcard syntax is used. Any address starting
-with `/news/politics/` will be automatically created by the broker.
-
-```xml
-<address-setting match="/news/politics/#">
- <auto-create-addresses>true</auto-create-addresses>
- <default-address-routing-type>MULTICAST</default-address-routing-type>
-</address-setting>
-```
-
-### Auto Address Deletion
-
-- Edit the file `<broker-instance>/etc/broker.xml` and add the
- `auto-delete-addresses` element to the `address-setting` you want the broker
to
- automatically delete.
-
-- (Optional) Add the `address-setting` if it does not exist. Use the match
- parameter and the [wildcard syntax](wildcard-syntax.md) to match more than
one
- specific address.
-
-- Set `auto-delete-addresses` to `true`
-
-The example below configures an `address-setting` to be automatically deleted
-by the broker. Note that wildcard syntax is used. Any address request by the
-client that starts with `/news/politics/` is configured to be automatically
-deleted by the broker.
-
-```xml
-<address-setting match="/news/politics/#">
- <auto-delete-addresses>true</auto-delete-addresses>
- <default-address-routing-type>MULTICAST</default-address-routing-type>
-</address-setting>
-```
-
-## "Fully Qualified" Queue Names
-
-Internally the broker maps a client’s request for an address to specific
-queues. The broker decides on behalf of the client which queues to send
-messages to or from which queue to receive messages. However, more advanced use
-cases might require that the client specify a queue directly. In these
-situations the client uses a fully qualified queue name, by specifying both
-the address name and the queue name, separated by `::`.
-
-> **Note**
->
-> The string `::` should only be used for FQQN and not in any other context
-> in address or queue names.
-
-Currently Artemis supports fully qualified queue names on Core, AMQP, JMS,
-OpenWire, MQTT and STOMP protocols for both sending and receiving messages.
-
-### Specifying a Fully Qualified Queue Name
-
-In this example, the address foo is configured with two queues q1, q2 as shown
-in the configuration below.
+Define `<multicast/>` with no queues and the broker will automatically create
+queues for each subscription when the consumers connect to `address.foo`. Then
+when a message is sent to `address.foo` it will be routed to each queue for
+each subscriber and therefore each subscriber will get every message. These
+queues are often referred to as _subscription queues_ for obvious reasons.
+
+These subscription queues are typically named based on the semantics of the
+protocol used to create them. For example, JMS supports durable and non-durable
+subscriptions. The queue for a non-durable subscription is named with a UUID,
+but the queue used for a durable subscription is named according to the JMS
+"client ID" and "subscription name." Similar conventions are used for AMQP,
+MQTT, STOMP, etc.
+
+## Advanced Manual Configuration
+
+### Fully Qualified Queue Names
+
+In most cases it’s not necessary or desirable to statically configure the
+aforementioned subscription queues. However, there are scenarios where a user
+may want to statically configure a subscription queue and later connect to that
+queue directly using a **Fully Qualified Queue Name** (i.e. FQQN).
+
+An FQQN uses a special syntax to specify *both* the address and the queue so
+that applications using protocols and APIs which don't natively understand the
+address/queue separation (e.g. AMQP, JMS, etc.) can send messages or subscribe
+*directly* to a queue rather than being limited to the address. Applications
+simply need to use the address name and the queue name separated by `::` (e.g.
+`address::queue`).
+
+In this example, the address `a1` is configured with two queues: `q1`, `q2` as
+shown in the configuration below.
```xml
<addresses>
- <address name="foo">
- <anycast>
+ <address name="a1">
+ <multicast>
<queue name="q1" />
<queue name="q2" />
- </anycast>
+ </multicast>
</address>
</addresses>
```
-In the client code, use both the address name and the queue name when
-requesting a connection from the broker. Remember to use two colons, `::`, to
-separate the names, as in the example Java code below.
+Here's a snippet of Java code using JMS which demonstrates the FQQN syntax:
```java
-String FQQN = "foo::q1";
+String FQQN = "a1::q1";
Queue q1 session.createQueue(FQQN);
Review comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]