2018-02-20 03:39:37 -05:00
|
|
|
# Exclusive Queues
|
|
|
|
|
|
|
|
Exclusive queues are special queues which route all messages to only one
|
|
|
|
consumer at a time.
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
This is useful when you want all messages to be processed serially by the same
|
|
|
|
consumer, when a producer does not specify [Message Grouping](message-grouping.md).
|
2018-02-20 03:39:37 -05:00
|
|
|
|
|
|
|
An example might be orders sent to an address and you need to consume them
|
|
|
|
in the exact same order they were produced.
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
Obviously exclusive queues have a draw back that you cannot scale out the
|
|
|
|
consumers to improve consumption as only one consumer would technically be active.
|
2018-02-20 03:39:37 -05:00
|
|
|
Here we advise that you look at message groups first.
|
|
|
|
|
|
|
|
|
|
|
|
## Configuring Exclusive Queues
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
Exclusive queues can be statically configured using the `exclusive` boolean
|
|
|
|
property:
|
2018-02-20 03:39:37 -05:00
|
|
|
|
|
|
|
```xml
|
2018-03-09 10:07:38 -05:00
|
|
|
<address name="foo.bar">
|
|
|
|
<multicast>
|
|
|
|
<queue name="orders1" exclusive="true"/>
|
|
|
|
</multicast>
|
|
|
|
</address>
|
2018-02-20 03:39:37 -05:00
|
|
|
```
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
Specified on creating a Queue by using the CORE api specifying the parameter
|
|
|
|
`exclusive` to `true`.
|
2018-02-20 03:39:37 -05:00
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
Or on auto-create when using the JMS Client by using address parameters when
|
|
|
|
creating the destination used by the consumer.
|
2018-02-20 03:39:37 -05:00
|
|
|
|
2018-03-08 15:46:38 -05:00
|
|
|
```java
|
|
|
|
Queue queue = session.createQueue("my.destination.name?exclusive=true");
|
|
|
|
Topic topic = session.createTopic("my.destination.name?exclusive=true");
|
|
|
|
```
|
2018-02-20 03:39:37 -05:00
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
Also the default for all queues under and address can be defaulted using the
|
|
|
|
`address-setting` configuration:
|
2018-02-20 03:39:37 -05:00
|
|
|
|
2018-03-08 15:46:38 -05:00
|
|
|
```xml
|
|
|
|
<address-setting match="lastValueQueue">
|
|
|
|
<default-exclusive-queue>true</default-exclusive-queue>
|
|
|
|
</address-setting>
|
|
|
|
```
|
2018-02-20 03:39:37 -05:00
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
By default, `default-exclusive-queue` is `false`. Address
|
|
|
|
[wildcards](wildcard-syntax.md) can be used to configure exclusive queues for a
|
|
|
|
set of addresses.
|
2018-02-20 03:39:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
See the [exclusive queue example](examples.md#exclusive) which shows how
|
|
|
|
exclusive queues are configured and used with JMS.
|