public Message process(Message message) throws ActionProcessingException
{
//The DeadLetterService is custom configurable Service. It is defined in
//the jbossesb.esb an by default it stores the message in the
//MessageStore under the DLQ categorization.
MessageStore ms = MessageStoreFactory.getInstance().getMessageStore();
Message rdlvrMessage = null;
message.getBody().add(ID, "ID:" + Integer.toHexString(System.identityHashCode(message))) ;
message.getBody().add(DATE, new Date()) ;
try {
//empty out the DLQ
Map<URI, Message> messageMap = ms.getAllMessages(MessageStore.CLASSIFICATION_RDLVR);
for (URI key : messageMap.keySet()) {
ms.removeMessage(key, MessageStore.CLASSIFICATION_RDLVR);
}
Service noneExistingService = new Service("none-exising-category", "none-existing-service-name");
ServiceInvoker si = new ServiceInvoker(noneExistingService);
si.deliverAsync(message);
//Adding this control code to show where the message now is.
Map<URI, Message> rdlvrMessageMap = ms.getAllMessages(MessageStore.CLASSIFICATION_RDLVR);
while (rdlvrMessageMap.size() == 0) { //we may have to wait for the DLQService to act.
logger.info("...Waiting for the DLQ Service to act.");
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
logger.error(ie);
}
rdlvrMessageMap = ms.getAllMessages(MessageStore.CLASSIFICATION_RDLVR);
}
for (URI key : rdlvrMessageMap.keySet()) {
rdlvrMessage = rdlvrMessageMap.get(key);
logger.info("*******************************");
logger.info("Message in the RDLVR should be the same message: " + compare(message.getBody(), rdlvrMessage.getBody()));
logger.info("Message=" + message.getBody());
logger.info("rdlvrMessage=" + rdlvrMessage.getBody());
logger.info("*******************************");
logger.info("Removing message to avoid future redeliveries");
ms.removeMessage(key, MessageStore.CLASSIFICATION_RDLVR);
}
} catch (MessageStoreException mse) {
throw new ActionProcessingException(mse.getMessage(), mse);
} catch (MessageDeliverException mde) {
throw new ActionProcessingException(mde.getMessage(), mde);