You can add a custom property to the message - like RESUBMIT_TIMES, and increment that until 5 is reached. Read this : JMS
if 5 is reached move it to the 5minutesqueue, by setting another property there that has the current timestamp. For example:
message.setStringProperty("TimeOfDispatch", LocalDate.now().toString("yyyy-MM-dd hh:MM:ss"));
Have yet another consumer on the 5minutesqueue that check if 5 minutes have passed(by checking current time with the time from the header)