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

67 lines
3.8 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. -->
<!-- ============================================================================= -->
<chapter id="last-value-queues">
<title>最新值队列Last-Value Queues</title>
<para>最新值队列是一种特殊的队列。当一个新消息到达一个最新值队列时它会将所有与该消息定义的Last-Value相同的旧消息
抛弃。换句话说,只有最新的消息被保留下来。</para>
<para>一个典型的用例是股价信息,通常你只关心一支股票的最新价格。</para>
<section>
<title>最新值队列的配置</title>
<para>最新值队列的配置在address-setting内</para>
<programlisting>
&lt;address-setting match="jms.queue.lastValueQueue"&gt;
&lt;last-value-queue&gt;true&lt;/last-value-queue&gt;
&lt;/address-setting&gt;
</programlisting>
<para>默认的<literal>last-value-queue</literal>值是false。可以使用通配符来匹配地址。
(参见 <xref linkend="wildcard-syntax"/>)。</para>
</section>
<section>
<title>使用Last-Value参数</title>
<para>用来标识最新值的参数名是<literal>"_HQ_LVQ_NAME"</literal>
相当于核心API中定义的常量<literal>Message.HDR_LAST_VALUE_NAME</literal>)。</para>
<para>如果两个消息具有相同的Last-Value值那么较新的消息就会保留另外一个被丢弃</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>例子</title>
<para>参见<xref linkend="examples.last-value-queue"/>。它展示的是在JMS应用中来配置和使用
最新值队列。</para>
</section>
</chapter>