Last-Value Queues | ActiveMQ Artemis Documentation

- 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

# Last-Value Queues

Last-Value queues are special queues which discard any messages when a newer message with the same value for a well-defined Last-Value property is put in the queue. In other words, a Last-Value queue only retains the last value.

A typical example for Last-Value queue is for stock prices, where you are only interested by the latest value for a particular stock.

## Configuring Last-Value Queues

Last-value queues are defined in the address-setting configuration:

    <address-setting match="jms.queue.lastValueQueue">
       <last-value-queue>true</last-value-queue>
    </address-setting>

By default, `last-value-queue` is false. Address wildcards can be used to configure Last-Value queues for a set of addresses (see here).

## Using Last-Value Property

The property name used to identify the last value is `"_AMQ_LVQ_NAME"` (or the constant `Message.HDR_LAST_VALUE_NAME` from the Core API).

For example, if two messages with the same value for the Last-Value property are sent to a Last-Value queue, only the latest message will be kept in the queue:

    // send 1st message with Last-Value property set to STOCK_NAME
    TextMessage message = session.createTextMessage("1st message with Last-Value property set");
    message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME");
    producer.send(message);

    // send 2nd message with Last-Value property set to STOCK_NAME
    message = session.createTextMessage("2nd message with Last-Value property set");
    message.setStringProperty("_AMQ_LVQ_NAME", "STOCK_NAME");
    producer.send(message);

    ...

    // only the 2nd message will be received: it is the latest with
    // the Last-Value property set
    TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
    System.out.format("Received message: %s\n", messageReceived.getText());

## Example

See the examples chapter for an example which shows how last value queues are configured and used with JMS.