2 Replies Latest reply on Feb 7, 2017 12:59 AM by manu29585

    Send an email after to admin after expiry of max-delivery-attempts

    manish.mj07

      Hello friends,

       

      Need your guidance for JMS(HornetQ):

       

      I want to configure email functionality if dead letter queue not completed job in specified time and max attempts.

      I mean,an email should be sent out by dead queue to inform user that queue moved to expiry queue and take the action ( in my, case expiry queue will store pdf file in local disk, later on, we will place pdf to ftp location manually).

       

      Hoping quick response.

       

      Thanks,

      Manish

        • 1. Re: Send an email after to admin after expiry of max-delivery-attempts
          jbertram

          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

            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()");

                    }

            }

            }