Friday, March 13, 2015

JMS Listener:



This makes Message handling is loosely coupled with either subscriber /Receiver

MessageListener is an interface which is available in the JMS package. which facilitates the Listner
for a message and send an event to either a Subscriber / Receiver.

This interface contain on method .

public void onMessage(Message msg);

Provide an implimentation to this in your own class

import javax.jms.*;

public class JMSListener implements MessageListener
{

    public void onMessage(Message msg)
    {
        try{
           
            TextMessage tm  = (TextMessage) msg;
            System.out.println(tm.getText());

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


configure this JMSListener in the subscriber,

    tSubscriber.setMessageListener(new JMSListener());

0 comments:

Post a Comment