aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JMS temporary queue weblogic 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 temporary queue weblogic" Watch "JMS temporary queue weblogic" New topic
Author

JMS temporary queue weblogic

Harischandra Reddy C
Greenhorn

Joined: Aug 08, 2002
Posts: 3
I am facing a problem in working with temporary queue using weblogic.Could any one help on this...
I have created template and all other settings have been done to use temporary queue.

I have a client which sends a message to a physical queue and also listens to the temporary queue. The temporary queue is created in the client program.
The receiver receives the message and sends it to the temporaryqueue.
The receiver is able to send the message to the temporary queue.
But the on message method in the client program which is listening to the temporary queue is not getting activated....
The output in the cleint side is :
F:\JMS_research\test2\MDBS>java TemporaryQ
Trying to create q connection.....
q connection created....
Trying to create q session.....
q session is created....weblogic.jms.client.JMSSession@335207
TempQ:examplesJMSServer.TemporaryQueue302

The output in the server is:
This is receiver1....
Message Received
Message has been received...from hari's machine
Sending message to hari's machine
Lookup of JMSConnectionTQ has been done...
qconnection has been created..
qsession has been created..
examplesJMSServer.TemporaryQueue302
qSend has been created..
Message has been created..
First message has been sent...
Message has been sent..
The client code is:---------------------
import javax.jms.*;
import javax.naming.*;
import java.util.*;
import java.io.*;
import oracle.xml.parser.v2.*;
import org.w3c.dom.*;
public class TemporaryQ{
static Object waitUntilDone = new Object();
public static void main (String[] args) {
InitialContext ctx = null;

QueueConnectionFactory queueConnectionFactory = null;
QueueConnection qConnection = null;
QueueSession qSess = null;
Queue replyQueue = null;
Queue que=null;
QueueReceiver qReceiver = null;
QueueSender qSend = null;
/*
* Create a JNDI API InitialContext object.
*/
try {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://192.9.200.42:7001");
ctx = new InitialContext(props);
} catch (NamingException e) {
System.err.println("TemporaryQ: " +
"Could not create JNDI API context: " +
e.toString());
System.exit(1);
}
/*
* Look up connection factories and topic. If any do not
* exist, exit.
*/
try {
queueConnectionFactory = (QueueConnectionFactory) ctx.lookup("JMSConnectionTQ");
que = (Queue) ctx.lookup("JMSQueueTQ");
//ctx.lookup("JMSConnectionTQ");
} catch (NamingException e) {
System.err.println("TemporaryQ: " +
"JNDI API lookup failed: " + e.toString());
System.exit(1);
}

try {
System.out.println("Trying to create q connection.....");
qConnection = queueConnectionFactory.createQueueConnection();
System.out.println("q connection created....");
System.out.println("Trying to create q session.....");
qSess = qConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
System.out.println("q session is created...."+qSess);
replyQueue = qSess.createTemporaryQueue();
System.out.println("TempQ:"+replyQueue);
qReceiver = qSess.createReceiver(replyQueue);
qReceiver.setMessageListener(new TQListener());
qConnection.start();
}catch(JMSException je)
{
System.out.println("The error is:"+je);
}
XMLDocument doc1 = null;
//XMLDocument doc2 = null;
try {
InputStream in = new FileInputStream("sender1.xml");
DOMParser theParser = new DOMParser();
theParser.parse(in);
doc1 = theParser.getDocument();
} catch (Exception e) {
e.printStackTrace();
}
try{
ObjectMessage objMsg1 = qSess.createObjectMessage();
objMsg1.setObject((XMLDocument)doc1);
qSend = qSess.createSender(que);
objMsg1.setJMSReplyTo(replyQueue);
objMsg1.setStringProperty("TempQMsg","Message Received");
qSend.send(objMsg1);
synchronized (waitUntilDone) {
waitUntilDone.wait();
}
} catch (Exception e) {
System.err.println("HumanResourceClient: " +
"Exception: " + e.toString());
}
}
/**
* The TQListener class implements the MessageListener
* interface by defining an onMessage method.
*/
static class TQListener implements MessageListener {
/**
* onMessage method, which displays the contents of a
* MapMessage describing the results of processing the
* new employee, then removes the employee ID from the
* list of outstanding requests.
*
* @param message the incoming message
*/
ObjectMessage objMsg=null;
public void onMessage(Message message) {
System.out.println("Inside on message method");
try{
if(message instanceof ObjectMessage)
{
objMsg = (ObjectMessage)message;
System.out.println("message has been received in the client side..");
}else{
// msg = message;
}
objMsg.acknowledge();
} catch(Exception ex1){
System.out.println("Exception in reading from queue");
ex1.printStackTrace();
}

synchronized(waitUntilDone) {
waitUntilDone.notify();
}
}
}
}
The receiver code is:---------------------------------------
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.jms.*;
import java.util.*;
import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
import oracle.xml.parser.v2.*;
import org.w3c.dom.*;
import java.io.*;
public class ReceiverTQ implements MessageDrivenBean, MessageListener
{
QueueConnectionFactory qConnFact = null;
Queue que = null;
QueueConnection qConn = null;
QueueSession qSess = null;
QueueSender qSend = null;
TextMessage message = null;
org.w3c.dom.Element bankNode = null;
InitialContext ic = null;
transient private Destination replyDestination;
MessageDrivenContext mdc = null;
//String selector="MessageName LIKE 'isValid'";

ObjectMessage objMsg=null;
//Message msg = null;
public void ejbActivate(){}
public void ejbRemove(){}
public void ejbPassivate(){}
public void ejbCreate () throws CreateException{}
public void setMessageDrivenContext(MessageDrivenContext ctx){
this.mdc = ctx;
}

public void onMessage(Message message)
{
System.out.println("This is receiver1....");
receiveMsg(message);
System.out.println("Message has been received...from hari's machine");
sendMsg();
// System.out.println("Message has been sent to hari's machine");
}
private Destination getReplyDestination() {
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
byte[] srd = new byte[1000];
//srd = getSerializedReplyDestination();
if (replyDestination == null && srd != null) {
try {
bais = new ByteArrayInputStream(srd);
ois = new ObjectInputStream(bais);
replyDestination = (Destination)ois.readObject();
ois.close();
} catch (IOException io) {
} catch (ClassNotFoundException cnfe) {}
}
return replyDestination;
}
private void setReplyDestination(Destination
replyDestination) {
ByteArrayOutputStream baos = null;
ObjectOutputStream oos = null;
this.replyDestination = replyDestination;
try {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(replyDestination);
oos.close();
//setSerializedReplyDestination(baos.toByteArray());
} catch (IOException io) {
}
}

public void receiveMsg(Message message)
{
try{
//setReplyDestination(message.getJMSReplyTo());
if(message instanceof ObjectMessage)
{
objMsg = (ObjectMessage)message;
System.out.println(objMsg.getStringProperty("TempQMsg"));
}else{
// msg = message;
}
objMsg.acknowledge();
// msg.acknowledge();

} catch(Exception ex1){
System.out.println("Exception in reading from queue");
ex1.printStackTrace();
}

}
public void sendMsg()
{
System.out.println("Sending message to hari's machine");
try{
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://192.9.200.42:7001");
ic = new InitialContext(props);
}
catch(Exception e){
System.out.println("Error is:"+e);
}
try {
qConnFact = (QueueConnectionFactory) ic.lookup("JMSConnectionTQ");
System.out.println("Lookup of JMSConnectionTQ has been done...");
que = (Queue) ic.lookup("JMSQueue1");
// System.out.println("Lookup of replyQueue has bebn done...");
} catch(Exception ex){
System.out.println("Error is");
ex.printStackTrace();
}
try{
qConn = qConnFact.createQueueConnection();
System.out.println("qconnection has been created..");
qSess = qConn.createQueueSession(true,0);
System.out.println("qsession has been created..");
//qSend = qSess.createSender(que);
//qSend = qSess.createSender(null);
qSend = qSess.createSender((Queue)objMsg.getJMSReplyTo());
System.out.println((Queue)objMsg.getJMSReplyTo());
System.out.println("qSend has been created..");
//System.out.println("The queue is:"+que.getQueueName());
ObjectMessage objMsg1 = qSess.createObjectMessage();
objMsg1.setObject((XMLDocument)objMsg.getObject());
System.out.println("Message has been created..");
//qSend.send(objMsg,DeliveryMode.PERSISTENT,objMsg.getJMSPriority(),0);
//qSend.send(objMsg1);
qSend.send(objMsg1);
System.out.println("First message has been sent...");
// qSend.send((Queue)getReplyDestination(),objMsg1);
System.out.println("Message has been sent..");
//qSend.send((Queue)objMsg1.getJMSReplyTo(),objMsg1);
//objMsg1.acknowledge();
//System.out.println("Priority is"+objMsg1.getJMSPriority());
//qSend.send(msg);

qConn.close();
} catch(Exception ex1){
System.out.println("Exception in sending to queue");
ex1.printStackTrace();
}
}

}


Regards<br />Harischandra Reddy C
 
Consider Paul's rocket mass heater.
 
subject: JMS temporary queue weblogic