message = session.createTextMessage("5 Second Expiration");
message.setJMSExpiration(System.currentTimeMillis() + 5*1000);
sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
// Send a message that has not expired
message = session.createTextMessage("OK");
sender.send(message);
// Sleep 6 seconds
Thread.sleep(6*1000);
// Try to receive the OK message
message = (TextMessage) receiver.receiveNoWait();
assertEquals("5 Second Expiration", message.getText());