-
1. Re: Send an email after to admin after expiry of max-delivery-attempts
jbertram May 25, 2016 12:39 PM (in response to manish.mj07)When a message is placed on the relevant DLQ you can have a client which consumes the message, sends the appropriate email, and then places the message into another queue to be dealt with later. HornetQ has no built-in email functionality to support this kind of use-case natively.
-
2. Re: Send an email after to admin after expiry of max-delivery-attempts
manu29585 Feb 7, 2017 12:59 AM (in response to manish.mj07)If this is in context of J2EE, What has been done is to consume as a MDB from DLQ as shown below:
You could additionally add email logic to this:
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@MessageDriven(name = "DLQProcessorMDBean",activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/DLQ")})
@ResourceAdapter("jms-ra.rar")
public class DLQMDBean implements MessageListener {
public void onMessage(Message msg) {
HierarchicalStreamWriter xwriter= null;
File dir = new File(DLQ_MESSAGE_FILE_PATH);
//creates directory
if(!dir.mkdirs()){
log.noI18nDebug("directory exist or IO error ocurred");
}
//Don't process ahead if write permission into directory is not granted
if (!dir.setWritable(true, false)) {
log.noI18nWarn("Error: DLQ messages dumps permision setting failed!");
return ;
}
if (!(msg instanceof ObjectMessage)) {
log.noI18nInfo("Input message is not an JMS ObjectMessage to process , so skip it");
return;
}
try {
ObjectMessage objMsg = (ObjectMessage) msg;
// obtain context from message object
msg = (Context) objMsg.getObject();
if(StringUtils.isEmptyString(msg)){
return;
}
// create file name using context's attributes and current dateTime
createFileName(context);
XStream xstream = new XStream();
BufferedOutputStream fos;
fos = new BufferedOutputStream(new FileOutputStream(dlqMessageFileName));
HierarchicalStreamDriver xdriver = new com.thoughtworks.xstream.io.xml.DomDriver();
xwriter = xdriver.createWriter(fos);
// create root-node "message"
xwriter.startNode("message");
xwriter.addAttribute("startTime", new Date().toString());
xstream.marshal(msg, xwriter);
xwriter.flush();
log.noI18nDebug("Message from DLQ is saved into "+dlqMessageFileName);
}catch (FileNotFoundException ex) {
//log here
}catch (Exception e) {
//log here
} finally{
if(null!=xwriter){
xwriter.endNode();
xwriter.flush();
xwriter.close();
}
log.noI18nDebug("Finished DLQ onMessage()");
}
}
}