Hi
I am trying to recreate the solution found on javaworld for one of my
applications.
http://www.javaworld.com/javaworld/jw-07-2003/jw-0718-mdb.html?page=1,
basically using MDBs to concurrently do some work and then pass the
results back to a SLSB that called the MDB.
I cannot seem to get this to work, the MDB that is called never is
executed until the
MessageConsumer recv = session.createConsumer(replyQ);
Message m = recv.receive(10000);
Times out and then I get an error in glassfish v2 UR1
DirectConsumer:Caught Exception delivering
messagecom.sun.messaging.jmq.io.Packet cannot be cast to
com.sun.messaging.jms.ra.DirectPacket
It seems that the MDB is never executed and blocks with the call
recv.receive(10000); and then is called after 10s. Is this the correct
behaviour, I thought that MDB were executed in another thread? Why
should it block?
Here is my code below.
Thanks Glen
Method in SLSB:
Connection connection = null;
Session session = null;
String text = "hello";
try {
System.out.println("Sending " + text);
connection = searchDestFactory.createConnection();
session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQ = session.createTemporaryQueue();
MessageProducer messageProducer =
session.createProducer(searchDest);
TextMessage tm = session.createTextMessage();
tm.setText(text);
tm.setJMSReplyTo(replyQ);
messageProducer.send(tm);
System.out.println("Sent " + text);
MessageConsumer recv = session.createConsumer(replyQ);
connection.start();
Message m = recv.receive(10000);
tm = (TextMessage) m;
System.out.println(tm);
} catch (JMSException ex) {
System.out.println(ex);
} finally {
try {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
} catch (JMSException ex) {
System.out.println(ex);
}
}
-------------------------------------------------
onMessagein MDB
public void onMessage(Message message) {
TextMessage tm = (TextMessage) message;
Connection connection = null;
Session session = null;
try {
try {
System.out.println("Got " + tm.getText());
connection = searchDestFactory.createConnection();
session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer =
session.createProducer(tm.getJMSReplyTo());
String result = "hello " + tm.getText();
TextMessage newtm = session.createTextMessage();
newtm.setText(result);
newtm.setJMSCorrelationID(tm.getJMSMessageID());
messageProducer.send(newtm);
System.out.println("Sent " + result);
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
} catch (JMSException ex) {
ex.printStackTrace();
}
}