Hey @rohit0903 …! Welcome to the community! ?
So as @uherbst already suggested, you could have the broker delay the delivery of messages for you automatically by using some combination of max-ttl
and a DMQ, but if that doesn’t work for you, ok. Also, Solace is working on some specific “delayed delivery” features, so Solace users don’t need to use TTL and DMQs in the future. So stay tuned for that!
in the meantime, if you really want your app to do the 10 second delay, but don’t want to blow up your memory, then there are some options and things you could do that could slow down the delivery of messages into your app. Here are some thoughts, in no particular order:
- You could switch your app to a blocking receive() call, by not specifying a callback handler on your consumer. That way, your app controls how often it pulls data off the queue. JMS API
- If you want to stick with async/callback delivery, you can adjust some parameters that affect how fast messages are pulled from the queue and sent to your app. Namely:
- Guaranteed Message Window Size: a JMS Connection Factory property, this is how many messages can be “in-flight” from the broker to the API; by setting this to a very low number, it will slow down how many messages can be streamed across to the receiving application from the broker. JMS API
- Max Permitted Number of Delivered Unacked Messages: a queue property, this is how many messages can be “outstanding” from the queue, messages that have been delivered but not ACKnowledged by the client. Default is 10,000. If you set this to say 1000, then the broker will send you 1000 and then block until you start acknowledging the messages. Configuring Queues
Now, I’m assuming that you’re using Persistent messages, and using Client ACK mode, and only ACKing the messages once they have been sent “downstream” by your app after 10 seconds? Because if not, and your app crashes, then there might be some messages loss, right? Or are you using non-persistent?
One other thing. You’re using Spring, right? Are you aware we have a JCSMP Spring binder as well? JCSMP is our “native Solace” Java API, and our JMS API is a wrapper around that. JCSMP gives you more control over how you handle messages as it’s not constrained by the JMS spec. With JCSMP, you create a FlowReceiver to get data off a queue, and you can start()
and stop()
that Flow anytime you want, which is an effective tool in controlling message rates into the application.
Last thoughts: how accurate does this 10 second delay have to be? Because if (for example) you did get a huge flood of messages on your queue, and you couldn’t process them as fast as they were arriving, then you’d need to delay for less than 10 seconds for messages that were backlogged onto the queue. One hint to help could be: the sender/publisher application could insert a timestamp in the message header to give your “10-sec delay” app a better indication of how long it should actually delay each message.
Sorry for the long post! Hope that helps, let us know…! ?