I'm writing an application which interfaces with multiple brokers using the springboot java framework. I'm leveraging JMS to browse/read messages which are older than 4 hours. The main issue is trying to generate a unit test for this functionality. This is because the test would have to send an old message to the broker and based on the article I read here, which explains that altering the Timestamp does nothing since it resets once the message is sent to the broker. Basically the article rendering any chance of the message being old. Does anyone have some work around? or know of a way I can achieve this?

I've already tried setting the JMSTimestamp message.setJMSTimestamp(System.currentTimeMillis() - 14400000). At run time it shows the timestamp being 4 hours old but checking the message in jconsole only shows it as the current date/time (Ex. Wed Apr 14 13:41:27 EDT 2021).

1

There are 1 answers

1
Sachin On BEST ANSWER

Rather trying to simulate the 4hr back use-case better way is to make that time (4hr) configurable. And set something like 10-15 sec to run a test for old message. You can do this by simply sending messages and waiting 15 sec before reading.

Otherwise, seems like your application is pivoting on timestamp when the message is received by broker rather that timestamp sent by producer.