이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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);

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);

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)

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)

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)

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)
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.