7 Replies Latest reply on Apr 21, 2014 9:31 AM by Clebert Suconic

    How to order a message to queue

    Ravi Teja Newbie

      HI

       

      Please find my question and description below

       

      For suppose i sent a message1 to the topic called TestTopic and i have a divert from TestTopic to the TestQueue . Now ,  I have a requirement saying that , When the TestQueue listens the message1 the request will process ,  When the message1 request is processing it takes some time to complete . After completion of message1 request i have to process the message2 in the same listener (TestQueue) .

       

      But , The problem here is

      when the message1 is processing , Simultaneously the message2 is processing.But , I have to process one by one after completing the each request

        • 1. Re: How to order a message to queue
          Yong Hao Gao Master

          I think you need to limit your TestQueue consumers to only one.

          • 2. Re: How to order a message to queue
            Ravi Teja Newbie

            Hi Yong Hao Gao ,

             

            Thank you for reply. But , I don't have any idea about to limit the TestQueue and how it works..?Could you please help me out

            • 3. Re: How to order a message to queue
              Yong Hao Gao Master

              Do you have some code showing how you receive and process messages from testQueue?

               

              Howard

              • 4. Re: How to order a message to queue
                Ravi Teja Newbie

                package com.vmchannel.listener;

                 

                 

                import javax.ejb.ActivationConfigProperty;

                import javax.ejb.MessageDriven;

                import javax.inject.Inject;

                import javax.jms.Message;

                import javax.jms.MessageListener;

                import javax.jms.ObjectMessage;

                 

                 

                import org.jboss.ejb3.annotation.ResourceAdapter;

                import org.slf4j.Logger;

                import org.slf4j.LoggerFactory;

                 

                 

                import com.common.exception.ApplicationException;

                import com.common.utils.ApplicationConstants;

                import com.common.utils.JsonUtils;

                import com.communication.destination.Queues;

                import com.communication.message.ComponentMessage;

                import com.communication.message.IdentificationDetail;

                import com.communication.message.content.VoiceMessage;

                import com.vmchannel.model.IVMChannelModel;

                 

                 

                /**

                * Message-Driven Bean implementation class for: VoiceMessageListener

                */

                @MessageDriven(activationConfig = {

                        @ActivationConfigProperty(propertyName="messageSelector", propertyValue="MESSAGE_TYPE='VoiceMessage'"),

                        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

                        @ActivationConfigProperty(propertyName = "destination", propertyValue = Queues.VOICEMESSAGE_QUEUE), })

                @ResourceAdapter("hornetq-ra.rar")

                public class VMChannelListener implements MessageListener {

                 

                 

                  private @Inject IVMChannelModel vmChannelModel;

                 

                  /**

                  * Logger for this class

                  */

                  private Logger logger = LoggerFactory.getLogger(VMChannelListener.class);

                    /**

                     * Default constructor.

                     */

                    public VMChannelListener() {

                        // TODO Auto-generated constructor stub

                    }

                 

                  /**

                     * @see MessageListener#onMessage(Message)

                     */

                    @SuppressWarnings("unchecked")

                  public void onMessage(Message message) {

                    logger.info("VoiceMailListener onMessage(Message message) - START");

                    try {

                    ObjectMessage  objectMessage = (ObjectMessage) message;

                    ComponentMessage<VoiceMessage>  componentMessage =(ComponentMessage<VoiceMessage>) objectMessage.getObject();

                    logger.info("VoiceMessage Recieved : \n {} ",JsonUtils.toJson(componentMessage));

                    if (!(componentMessage==null)) {

                  VoiceMessage voiceMessage = componentMessage

                  .getMessageContent();

                  IdentificationDetail identificationDetail = componentMessage

                  .getIdentificationDetails();

                  if (!(voiceMessage == null) && !(identificationDetail == null)) {

                  vmChannelModel.processVoiceMessage(identificationDetail,

                  voiceMessage);

                 

                 

                  } else {

                  // VoiceMessage | IdentificationDetail Object is required to process

                  throw new ApplicationException(

                  ApplicationConstants.ES_VM_01);

                  }

                  }

                    else{

                    //ComponentMessage is null

                    throw new ApplicationException(

                  ApplicationConstants.ES_VM_01);

                    }

                  } catch (Exception e) {

                  logger.error("VoiceMailListener onMessage(Message message)",e);

                  }

                  

                       

                   

                    }

                 

                 

                }

                • 5. Re: How to order a message to queue
                  Ravi Teja Newbie

                  Hi Yong Hao Gao ,

                   

                  Please assume that there are multiple instance more than 2 like 4 jboss server instances and 2 hornetq servers.

                  • 6. Re: How to order a message to queue
                    Yong Hao Gao Master

                    Can you try adding:

                     

                    @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1"),


                    and see if it works?


                    I'm thinking if you need strict ordering you may want to have a look at 'message-group' feature with HornetQ. There are two examples for this. However because your use-case involves dirvert, you need to reconsider your design to adapt this feature. Maybe you can add a 'transformer' to the divert that using this feature.


                    Howard


                    • 7. Re: How to order a message to queue
                      Clebert Suconic Master

                      the MDB layer on the Resource Adapter will instantiate several consumers to process your message in parallel.

                       

                      You could either set the maxSession=1 as Howard pointed out, or keep using multiple sessions but also use Message Grouping (look on the manual for message grouping).

                       

                      However since you're using Topics, I guess it makes more session to just use maxSession=1. I'm just pointing out a bit more information for you.. but I think Howard (aka Yong Hao) has answered your question already.