此内容没有您所选择的语言版本。

Chapter 16. Configuring Message Expiry


Sent messages can be set to expire on the server if they are not delivered to a consumer after a specified amount of time. These expired messages can later be consumed for further inspection.

Set Message Expiry Using the Core API

Using the core API, you can set an expiration time on a message using the setExpiration method.

// The message will expire 5 seconds from now
message.setExpiration(System.currentTimeMillis() + 5000);
Copy to Clipboard Toggle word wrap

Set Message Expiry Using JMS

You can set the time to live for the JMS MessageProducer to use when sending messages. You specify this value, in milliseconds, using the setTimeToLive method.

// Messages sent by this producer will be retained for 5 seconds before expiring
producer.setTimeToLive(5000);
Copy to Clipboard Toggle word wrap

You can also specify the message expiry on a per-message basis by setting the time to live on the producer’s send method.

// The last parameter of the send method is the time to live, in milliseconds
producer.send(message, DeliveryMode.PERSISTENT, 0, 5000)
Copy to Clipboard Toggle word wrap

Expired messages that are consumed from an expiry address have the following properties.

  • _AMQ_ORIG_ADDRESS

    A String property containing the original address of the expired message.

  • _AMQ_ACTUAL_EXPIRY

    A Long property containing the actual expiration time of the expired message.

16.1. Expiry Address

You can specify where to send expired messages by setting an expiry address. If a message expires and no expiry address is specified, the message is removed from the queue and dropped.

You can set an expiry-address for an address-setting using the management CLI. In the below example, expired messages in the jms.queue.exampleQueue queue will be sent to the jms.queue.expiryQueue expiry address.

/subsystem=messaging-activemq/server=default/address-setting=jms.queue.exampleQueue:write-attribute(name=expiry-address,value=jms.queue.expiryQueue)
Copy to Clipboard Toggle word wrap

16.2. Expiry Reaper Thread

A reaper thread periodically inspects the queues to check whether messages have expired. You can set the scan period and thread priority for the reaper thread using the management CLI.

Set the scan period for the expiry reaper thread, which is how often, in milliseconds, the queues will be scanned to detect expired messages. The default is 30000. You can set this to -1 to disable the reaper thread.

/subsystem=messaging-activemq/server=default:write-attribute(name=message-expiry-scan-period,value=30000)
Copy to Clipboard Toggle word wrap

Set the thread priority for the expiry reaper thread. Possible values are from 0 to 9, with 9 being the highest priority. The default is 3.

/subsystem=messaging-activemq/server=default:write-attribute(name=message-expiry-thread-priority,value=3)
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat