Questo contenuto non è disponibile nella lingua selezionata.

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
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat