activemq-artemis/docs/user-manual/zh/message-expiry.xml

82 lines
4.9 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="message-expiry">
<title>过期的消息</title>
<para>消息在发送时有一个可选的<emphasis>生存时间</emphasis>属性。</para>
<para>如果一个消息已经超过了它的生存时间HornetQ不再将它传递给任何接收者。
服务器会将过期的消息抛弃。</para>
<para>HornetQ的地址可以配置一个过期地址当消息过期时它们被从队列中删除并被转移到过期地址中。
多个不同的队列可以绑定到一个过期地址上。这些过期的消息过后可以接收下来以供分析用。</para>
<section>
<title>过期消息的配置</title>
<para>如果使用HornetQ核心API可以直接在消息上设置过期时间</para>
<programlisting>
// message will expire in 5000ms from now
message.setExpiration(System.currentTimeMillis() + 5000);
</programlisting>
<para>JMS的MessageProducer可以设置一个TimeToLive来控制其发送的消息</para>
<programlisting>
// messages sent by this producer will be retained for 5s (5000ms) before expiration
producer.setTimeToLive(5000);
</programlisting>
<para>从过期地址中接收下来的消息有以下属性:</para>
<itemizedlist>
<listitem>
<para><literal>_HQ_ORIG_ADDRESS</literal></para>
<para>这是一个字符串,它是该消息的<emphasis>原始地址</emphasis></para>
</listitem>
<listitem>
<para><literal>_HQ_ACTUAL_EXPIRY</literal></para>
<para>一个长整型量,代表此消息<emphasis>实际过期时间</emphasis></para>
</listitem>
</itemizedlist>
</section>
<section id="message-expiry.configuring">
<title>配置过期地址</title>
<para>过期地址配置在地址设置address-setting</para>
<programlisting>
&lt;!-- expired messages in exampleQueue will be sent to the expiry address expiryQueue --&gt;
&lt;address-setting match="jms.queue.exampleQueue"&gt;
&lt;expiry-address&gt;jms.queue.expiryQueue&lt;/expiry-address&gt;
&lt;/address-setting&gt;
</programlisting>
<para>如果没有定义过期地址,当一个消息过期时,它将被删除。配置过期地址时可以使用通配符
来给一组地址配置过期地址。(参见<xref linkend="wildcard-syntax"/>)。</para>
</section>
<section id="configuring.expiry.reaper">
<title>配置过期回收线程</title>
<para>HornetQ有一个回收线程定期地检查队列中的消息目的是发现是否有消息过期。</para>
<para><literal>hornetq-configuration.xml</literal>文件中可以对回收线程进行配置,参数如下:</para>
<itemizedlist>
<listitem>
<para><literal>message-expiry-scan-period</literal></para>
<para>过期消息的扫描间隔单位毫秒默认为30000ms。如要关闭扫描将其设为<literal>-1</literal></para>
</listitem>
<listitem>
<para><literal>message-expiry-thread-priority</literal></para>
<para>回收线程的优先级为0到9的整数9优先级最高。默认是3</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>例子</title>
<para>参见<xref linkend="examples.expiry"/>。这个例子展示了在JMS中如何配置使用消息过期功能。</para>
</section>
</chapter>