• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JMS Request/Reply mode

 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please try MessageSelector.
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic