Itay Moav -Malimovka
Itay Moav -Malimovka

Reputation: 53607

How to get only the last message in a group in Apache ActiveMQ "Classic"?

Scenario: Users are taking a long quiz. I store the current score and location in the quiz after each interaction. I want to store in the DB only the last interaction the user did during this current launch.

Right now I achieve this via Redis, were every time I store the last interaction I overwrite the previous one.

Can this be achieved via Apache's ActiveMQ "Classic" where each user can have his messages grouped and I consume only the last message received in the group?

Upvotes: 0

Views: 267

Answers (2)

Matt Pavlovich
Matt Pavlovich

Reputation: 4316

This can be done with an ActiveMQ 5.x Topic and a subscription recovery policy

You don't really need a queue when you enable this type of feature.

See LastImageSubscriptionRecoveryPolicy here: Subscription Recovery Policy

Upvotes: 0

Justin Bertram
Justin Bertram

Reputation: 35123

I'm not aware of any automated way to do this in ActiveMQ 5.x, but you can do with with ActiveMQ Artemis using a "last value" queue. This feature allows you to set a special property on a message to a particular value and any time another message with that same property value arrives on the queue it will replace the previous one.

To be clear, Artemis has backwards compatibility support for ActiveMQ 5.x clients (which using the OpenWire protocol).

Upvotes: 1

Related Questions