Iam working on activeMQ where iam sending a message to the consumer from producer via the queue.Assume that my consumer has failed due to some reason. I have set the expiry time to the message as 15 mins so the message from producer stays on the queue and expires after 15 minutes. How do i check programatically & ultimately get notified if the activeMQ message has expired or not in queue in producer only not in consumer(This is due my design).
The code snippet is as below.
Initialization code
public void init() {
try {
final LocalProperties config = new LocalProperties();
final ConnectionFactory factory = new ActiveMQConnectionFactory(config.getActiveMqConnection());
this.connection = factory.createConnection(config.getActiveMqUser(), config.getActiveMqPassword());
this.connection.start();
this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Destination destination = this.session.createQueue(QUEUE_NAME);
this.producer = this.session.createProducer(destination);
this.producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
} catch (final JMSException e) {
_LOG.error("We could not open the active mq connection", e);
}
}
Producer Code
public Response PostMessages(
final MessageDelivery body, final String messageId) {
try {
this.openConnection();
// Create a messages
final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
final String json = gson.toJson(body);
final TextMessage request = this.session.createTextMessage(json);
request.setLongProperty(
"expiryTime",
900000
);
request.setStringProperty("messageType", "com/messages/post");
request.setBooleanProperty("deliveryNotification", false);
request.setStringProperty("destination", "XXXX");
request.setStringProperty("destinationType", "FILTER");
_LOG.info(request.getText());
// Tell the producer to send the message
producer.send(request);
//How to get the expired message after producer.send(request)
return Response.status(Response.Status.ACCEPTED).build();
} catch (final Exception e) {
_LOG.error("We could not send the message", e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
}*