activemq-artemis/docs/user-manual/en/last-value-queues.xml

72 lines
4.1 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================================================= -->
<!-- Copyright © 2009 Red Hat, Inc. and others. -->
<!-- -->
<!-- The text of and illustrations in this document are licensed by Red Hat under -->
<!-- a Creative Commons AttributionShare Alike 3.0 Unported license ("CC-BY-SA"). -->
<!-- -->
<!-- An explanation of CC-BY-SA is available at -->
<!-- -->
<!-- http://creativecommons.org/licenses/by-sa/3.0/. -->
<!-- -->
<!-- In accordance with CC-BY-SA, if you distribute this document or an adaptation -->
<!-- of it, you must provide the URL for the original version. -->
<!-- -->
<!-- Red Hat, as the licensor of this document, waives the right to enforce, -->
<!-- and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent -->
<!-- permitted by applicable law. -->
<!-- ============================================================================= -->
<!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 "HornetQ_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>
&lt;address-setting match="jms.queue.lastValueQueue">
&lt;last-value-queue>true&lt;/last-value-queue>
&lt;/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>