71 lines
4.0 KiB
XML
71 lines
4.0 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- ============================================================================= -->
|
|
<!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
|
|
<!-- contributor license agreements. See the NOTICE file distributed with -->
|
|
<!-- this work for additional information regarding copyright ownership. -->
|
|
<!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
|
|
<!-- (the "License"); you may not use this file except in compliance with -->
|
|
<!-- the License. You may obtain a copy of the License at -->
|
|
<!-- -->
|
|
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
|
|
<!-- -->
|
|
<!-- Unless required by applicable law or agreed to in writing, software -->
|
|
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
|
|
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
|
|
<!-- See the License for the specific language governing permissions and -->
|
|
<!-- limitations under the License. -->
|
|
<!-- ============================================================================= -->
|
|
|
|
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
|
<!ENTITY % BOOK_ENTITIES SYSTEM "ActiveMQ_User_Manual.ent">
|
|
%BOOK_ENTITIES;
|
|
]>
|
|
<chapter id="last-value-queues">
|
|
<title>Last-Value Queues</title>
|
|
<para>Last-Value queues are special queues which discard any messages when a newer message with
|
|
the same value for a well-defined Last-Value property is put in the queue. In other words, a
|
|
Last-Value queue only retains the last value.</para>
|
|
<para>A typical example for Last-Value queue is for stock prices, where you are only interested
|
|
by the latest value for a particular stock.</para>
|
|
<section>
|
|
<title>Configuring Last-Value Queues</title>
|
|
<para>Last-value queues are defined in the address-setting configuration:</para>
|
|
<programlisting>
|
|
<address-setting match="jms.queue.lastValueQueue">
|
|
<last-value-queue>true</last-value-queue>
|
|
</address-setting></programlisting>
|
|
<para>By default, <literal>last-value-queue</literal> is false. Address wildcards can be used
|
|
to configure Last-Value queues for a set of addresses (see <xref linkend="wildcard-syntax"
|
|
/>).</para>
|
|
</section>
|
|
<section>
|
|
<title>Using Last-Value Property</title>
|
|
<para>The property name used to identify the last value is <literal>"_HQ_LVQ_NAME"</literal>
|
|
(or the constant <literal>Message.HDR_LAST_VALUE_NAME</literal> from the Core API).</para>
|
|
<para>For example, if two messages with the same value for the Last-Value property are sent to
|
|
a Last-Value queue, only the latest message will be kept in the queue:</para>
|
|
<programlisting>
|
|
// send 1st message with Last-Value property set to STOCK_NAME
|
|
TextMessage message = session.createTextMessage("1st message with Last-Value property set");
|
|
message.setStringProperty("_HQ_LVQ_NAME", "STOCK_NAME");
|
|
producer.send(message);
|
|
|
|
// send 2nd message with Last-Value property set to STOCK_NAME
|
|
message = session.createTextMessage("2nd message with Last-Value property set");
|
|
message.setStringProperty("_HQ_LVQ_NAME", "STOCK_NAME");
|
|
producer.send(message);
|
|
|
|
...
|
|
|
|
// only the 2nd message will be received: it is the latest with
|
|
// the Last-Value property set
|
|
TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
|
|
System.out.format("Received message: %s\n", messageReceived.getText());</programlisting>
|
|
</section>
|
|
<section>
|
|
<title>Example</title>
|
|
<para>See <xref linkend="examples.last-value-queue"/> for an example which shows how last
|
|
value queues are configured and used with JMS.</para>
|
|
</section>
|
|
</chapter>
|