jmsactivemq-artemis

ActiveMQ subscribe every n messages from a topic?


Assume messages are published very frequently on some topic and cause extreme network load to subscribe to all of the messages. In reality, we may just want a sample of these, say one every 10 messages or max 1 message per minute.

The only way I can think of doing this is with some publisher-side addition of a JMS header every n messages and then have clients select with the header, but it doesn’t give clients more granular control here.

Is there an alternative solution that I am not considering?

All my applications are using the OpenWire JMS clients shipped with ActiveMQ Classic.


Solution

  • There is no specific feature in ActiveMQ Artemis (or ActiveMQ Classic) to only receive every nth message. However, there are some features that may still be useful.

    The first thing that comes to mind is simply using the JMS API to limit the amount of messages consumed over a given time period by unsubscribing and resubscribing. For example, of the course of a minute the client might subscribe and listen for messages for 15 seconds then unsubscribe. Then after 30 seconds it would subscribe again.

    Other potential options:

    There may be other possibilities for your use-case, but it's hard to say for sure without more details.

    For what it's worth, I think the idea of a "drop-rate" for an address is an interesting idea. I've created ARTEMIS-5149 to track this.