aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JMS Request/Reply mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS Request/Reply mode" Watch "JMS Request/Reply mode" New topic
Author

JMS Request/Reply mode

Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,
I am using following Request, Response classes for to check the JMS Request/Reply mode in weblogic5.1. But in this case i am able to send the messages to the Queue Q1. But I observed that In weblogic console two temporary queues are created instead of one. And the response methods receive() is not working. Please help me to find out the solution.( If QueueRequestor will create one Temporary Queue then how it will be retrived in the Response class, or how to retrieve the same session. [*]In JMS API it has mentioned that Every QueueRequestor will create a temporaryQueue. )
Thanks in advance,
M.S.Raman.
__________________________________________________
**************************************************
1)Request class:
import javax.jms.*;
import javax.naming.*;
import java.util.*;
public class RequestMsg
{
public static void main(String args[])
{
Context ctx= null;
QueueConnectionFactory qcf=null;
Queue queue=null;
try
{

Hashtable ht= new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx= new InitialContext(ht);
}
catch(NamingException ne)
{
System.out.println("NamingException occured: " + ne);
}
try
{
qcf= (QueueConnectionFactory)ctx.lookup("javax.jms.QueueConnectionFactory");
queue= (Queue)ctx.lookup("Q1");
}
catch(NamingException ne1)
{
System.out.println("NamingException in lookup: " + ne1);
}

try
{
System.out.println("Created the QueueConnection");
QueueConnection queueConnection=qcf.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

QueueRequestor queueRequestor= new QueueRequestor(queueSession,queue);
TextMessage tMsg= queueSession.createTextMessage();
TemporaryQueue temporaryQueue= queueSession.createTemporaryQueue();
tMsg.setJMSCorrelationID("raman");
tMsg.setJMSReplyTo(temporaryQueue);
tMsg.setText("Hai Raman ....");
TextMessage RMsg=(TextMessage)queueRequestor.request(tMsg);
System.out.println("Message be requested Successfully: "+ RMsg.getText());
temporaryQueue.delete();
queueRequestor.close();
}catch(JMSException je)
{
System.out.println("JMSException occured:" + je);
}
}
}
**************************************************
2) Response class:

import javax.jms.*;
import javax.naming.*;
import java.util.*;
public class ResponseMsg
{
public static void main(String args[])
{

Context ctx=null;
QueueConnectionFactory qcf= null;
Queue queue=null;
try
{
Hashtable ht= new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx= new InitialContext(ht);
}
catch(NamingException ne)
{
System.out.println("NamingException occured: " + ne);
}

try
{
qcf= (QueueConnectionFactory)ctx.lookup("javax.jms.QueueConnectionFactory");
queue=(Queue) ctx.lookup("Q1");
}
catch(NamingException ne1)
{
System.out.println("naming Exception in lookup: " + ne1);
}

try
{
QueueConnection queueConnection = qcf.createQueueConnection();
QueueSession queueSession= queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
QueueReceiver queueReceiver= queueSession.createReceiver(queue);

TextMessage tMsg= (TextMessage)queueReceiver.receive();
String correlationID= tMsg.getJMSCorrelationID();
String txt= tMsg.getText();
System.out.println("The Message is : " + txt);

TemporaryQueue tq= (TemporaryQueue)tMsg.getJMSReplyTo();
TextMessage rMsg= queueSession.createTextMessage();
rMsg.setJMSCorrelationID(correlationID);
rMsg.setText(" Received your message : "+ txt);
QueueSender queueSender = queueSession.createSender(tq);
System.out.println("Message be send to the temp queue");
queueSender.send(tq,rMsg);
System.out.println(" Ended");

}
catch(JMSException je)
{
System.out.println("JMSException : " + je);
}

}
}
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
I Got the answer, In the above programme i did not start the connection.
__________________________________________________
1) RequestMessage:
import javax.jms.*;
import javax.naming.*;
import java.util.*;
public class RequestMsg
{
public static void main(String args[])
{

QueueConnectionFactory qcf=null;
QueueConnection queueConnection=null;
QueueSession queueSession =null;
Queue queue=null;
TextMessage message=null;
final String MSG_TEXT="This is a test Message";
TextMessage reply=null;
QueueRequestor queueRequestor=null;
Context ctx= null;
try
{

Hashtable ht= new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx= new InitialContext(ht);
}
catch(NamingException ne)
{
System.out.println("NamingException occured: " + ne);
}
try
{
qcf= (QueueConnectionFactory)ctx.lookup("javax.jms.QueueConnectionFactory");
queue= (Queue)ctx.lookup("Q1");
queueConnection=qcf.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,Session.CLIENT_ACKNOWLEDGE);

}
catch(Exception ne1)
{
System.out.println("NamingException in lookup: " + ne1);
if (queueConnection !=null)
{
try
{
queueConnection.close();
}catch(JMSException ee)
{
}
}
System.exit(1);

}

try
{
queueRequestor= new QueueRequestor(queueSession,queue);
message= queueSession.createTextMessage();
message.setText(MSG_TEXT);
System.out.println("REQUEST: Sending Messages: " + message.getText());
queueConnection.start();
reply=(TextMessage)queueRequestor.request(message);
System.out.println("REQUEST: Reply RECEIVED: "+ reply.getText());
}catch(JMSException je)
{
System.out.println("JMSException occured:" + je);
}
}
}
_________________________________________________
2) ResponseMsg:
import javax.jms.*;
import javax.naming.*;
import java.util.*;
public class ResponseMsg
{
public static void main(String args[])
{
QueueConnectionFactory queueConnectionFactory= null;
QueueConnection queueConnection = null;
QueueSession queueSession= null;
Queue queue=null;
QueueReceiver queueReceiver=null;
TextMessage message=null;
Queue tempQueue=null;
QueueSender replySender= null;
TextMessage reply=null;
final String REPLY_TEXT="Here is that message";
Context ctx=null;
try
{
Hashtable ht= new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx= new InitialContext(ht);
}
catch(NamingException ne)
{
System.out.println("NamingException occured: " + ne);
}

try
{
queueConnectionFactory= (QueueConnectionFactory)ctx.lookup("javax.jms.QueueConnectionFactory");
queue=(Queue) ctx.lookup("Q1");
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession= queueConnection.createQueueSession(false,Session.CLIENT_ACKNOWLEDGE);
}
catch(Exception ne1)
{
System.out.println("Exception in lookup: " + ne1);
if (queueConnection !=null)
{
try
{
queueConnection.close();
}catch(JMSException ee)
{
}
}
System.exit(1);

}

try
{
queueReceiver= queueSession.createReceiver(queue);
queueConnection.start();
message = (TextMessage)queueReceiver.receive();
System.out.println("REPLY : Message Received: " + message.getText());
Queue tq= (Queue)message.getJMSReplyTo();
replySender = queueSession.createSender(tq);
reply= queueSession.createTextMessage();
reply.setText(REPLY_TEXT);
reply.setJMSCorrelationID(message.getJMSMessageID());
System.out.println("REPLY: Sending Reply : "+ reply.getText());
replySender.send(reply);

}
catch(JMSException je)
{
System.out.println("JMSException : " + je);
}

}
}
Regards,
M.S.Raman.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,
While executing the above program i observed that if some other client can also receive the message posted by the requestMSG (as per FIFO basis and the RequestMSG will wait for the response). Then how it will become a reliable messaging framework, and what security is there for the message.
Regards,
M.S.Raman.
Abdul Salam
Greenhorn

Joined: Feb 25, 2002
Posts: 10
Please try MessageSelector.


Knowledge Xchange. SCJ2P.
 
Don't get me started about those stupid light bulbs.
 
subject: JMS Request/Reply mode