users@glassfish.java.net

Re: MDB Concurrency problem

From: Ramesh <Ramesh.Parthasarathy_at_Sun.COM>
Date: Fri, 13 Jun 2008 20:54:15 +0530

Hi,
Could you use the LOCAL mode as a workaround for this issue
Open admin console: http://localhost:4848, Select: Configuration ->
Java Message Service node in the tree on the left, Change the type from
"EMBEDDED" into "LOCAL", and restart glassfish.

Thanks
-Ramesh



Drinkwater, GJ (Glen) wrote:
> 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();
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>