Posted By:
R_Kannan
Posted On:
Thursday, April 18, 2002 10:01 PM
Hai, Usually for the Receiver application inorder to get reference of Message Interface, he has to register the listener and implement onMessage(Message msg) ,but I saw this example which is working fine without the help of Listener . ========================= public class QReceiver { public static void main(String[] args) { try{ InitialContext initContext = new InitialContext(); QueueConnectionFactory factory =(QueueConnectionFactory) initContext.lookup("factoryName"); Queue queue = (Queue) initContext.lookup("queueName");
More>>
Hai,
Usually for the Receiver application inorder to get reference of
Message
Interface, he has to register the listener and implement
onMessage(Message
msg)
,but I saw this example which is working fine without the help of
Listener
.
=========================
public class QReceiver
{
public static void main(String[] args)
{
try{
InitialContext
initContext = new InitialContext();
QueueConnectionFactory factory =(QueueConnectionFactory)
initContext.lookup("factoryName");
Queue queue = (Queue) initContext.lookup("queueName");
QueueConnection connection = factory.createQueueConnection();
QueueSession session =connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = session.createReceiver(queue);
connection.start();
Message msg = null;
String msgText = "";
do {
msg = receiver.receive();
if (msg instanceof TextMessage)
{
msgText = ((TextMessage)msg).getText();
System.out.println("Message Received = "+ msgText );
}
}while(msgText.equals("quit"));
} catch
(Exception e) {}
}
}
=========================
My Question is :
-
To receive the message without the help of
MessageListsener
is it
acceptable using the above code?If acceptable ,when to go for this knid of coding?
-
This program is it asynchronous behaviour or synchronous behaviour?
Thanks,
Ranga.
<<Less