- Introduction
- 1. Legal Notice
- 2. Preface
- 3. Project Info
- 4. Messaging Concepts
- 5. Architecture
- 6. Using the Server
- 7. Using JMS
- 8. Using Core
- 9. Mapping JMS Concepts to the Core API
- 10. The Client Classpath
- 11. Examples
- 12. Routing Messages With Wild Cards
- 13. Understanding the Apache ActiveMQ Artemis Wildcard Syntax
- 14. Filter Expressions
- 15. Persistence
- 16. Configuring Transports
- 17. Detecting Dead Connections
- 18. Detecting Slow Consumers
- 19. Resource Manager Configuration
- 20. Flow Control
- 21. Guarantees of sends and commits
- 22. Message Redelivery and Undelivered Messages
- 23. Message Expiry
- 24. Large Messages
- 25. Paging
- 26. Queue Attributes
- 27. Scheduled Messages
- 28. Last-Value Queues
- 29. Message Grouping
- 30. Extra Acknowledge Modes
- 31. Management
- 32. Security
- 33. Resource Limits
- 34. The JMS Bridge
- 35. Client Reconnection and Session Reattachment
- 36. Diverting and Splitting Message Flows
- 37. Core Bridges
- 38. Duplicate Message Detection
- 39. Clusters
- 40. High Availability and Failover
- 41. Graceful Server Shutdown
- 42. Libaio Native Libraries
- 43. Thread management
- 44. Logging
- 45. REST Interface
- 46. Embedding Apache ActiveMQ Artemis
- 47. Spring Integration
- 48. AeroGear Integration
- 49. VertX Integration
- 50. Intercepting Operations
- 51. Protocols and Interoperability
- 52. Tools
- 53. Maven Plugin
- 54. Troubleshooting and Performance Tuning
- 55. Configuration Reference
- Published using GitBook

# ActiveMQ Artemis Documentation

# Message Expiry

Messages can be set with an optional time to live when sending them.

Apache ActiveMQ Artemis will not deliver a message to a consumer after it's time to live has been exceeded. If the message hasn't been delivered by the time that time to live is reached the server can discard it.

Apache ActiveMQ Artemis's addresses can be assigned a expiry address so that, when messages are expired, they are removed from the queue and sent to the expiry address. Many different queues can be bound to an expiry address. These expired messages can later be consumed for further inspection.

## Message Expiry

Using Apache ActiveMQ Artemis Core API, you can set an expiration time directly on the message:

    // message will expire in 5000ms from now
    message.setExpiration(System.currentTimeMillis() + 5000);

JMS MessageProducer allows to set a TimeToLive for the messages it sent:

    // messages sent by this producer will be retained for 5s (5000ms) before expiration
    producer.setTimeToLive(5000);

Expired messages which 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_ORIG_QUEUE`

  a String property containing the original queue of the expired message

- `_AMQ_ACTUAL_EXPIRY`

  a Long property containing the actual expiration time of the expired message

## Configuring Expiry Addresses

Expiry address are defined in the address-setting configuration:

    <!-- expired messages in exampleQueue will be sent to the expiry address expiryQueue -->
    <address-setting match="jms.queue.exampleQueue">
       <expiry-address>jms.queue.expiryQueue</expiry-address>
    </address-setting>

If messages are expired and no expiry address is specified, messages are simply removed from the queue and dropped. Address wildcards can be used to configure expiry address for a set of addresses (see Understanding the Wildcard Syntax).

## Configuring The Expiry Reaper Thread

A reaper thread will periodically inspect the queues to check if messages have expired.

The reaper thread can be configured with the following properties in `broker.xml`

- `message-expiry-scan-period`

  How often the queues will be scanned to detect expired messages (in milliseconds, default is 30000ms, set to `-1` to disable the reaper thread)

- `message-expiry-thread-priority`

  The reaper thread priority (it must be between 1 and 10, 10 being the highest priority, default is 3)

## Example

See the examples.md chapter for an example which shows how message expiry is configured and used with JMS.