1 Reply Latest reply on Dec 15, 2003 6:48 AM by Adrian Brock

    Problem with jboss4.0DR2 Message Driven Bean

    fenor Newbie

      Hi,
      my name is Edoardo and I'm using Message Driven Bean with jboss4.0 DR2. I have some problem with topic.
      The strange thing is that everything is OK with jboss 3.2.x (I mean with the same configuration and source code).
      I try to send a textMessage from a client to a MDB via a topic, but I have the following error on jboss (so on the consumer):

      17:40:35,187 WARN [SpyMessageConsumer] Error in getMessage()
      javax.jms.JMSException: Invalid transaction id.
      at org.jboss.mq.SpyXAResourceManager.ackMessage(SpyXAResourceManager.jav
      a:72)
      at org.jboss.mq.SpyMessageConsumer.preProcessMessage(SpyMessageConsumer.
      java:714)
      at org.jboss.mq.SpyMessageConsumer.getMessage(SpyMessageConsumer.java:67
      7)
      at org.jboss.mq.SpyMessageConsumer.receive(SpyMessageConsumer.java:190)
      at org.jboss.resource.adapter.jms.MessageDelegate.run(MessageDelegate.ja
      va:60)
      at org.jboss.resource.work.WorkHolder.run(WorkHolder.java:143)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExec
      utor.java:732)
      at java.lang.Thread.run(Thread.java:534)


      Here following my code and my xml files.

      ------------------------------------------
      jboss.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC
      "-//JBoss//DTD JBOSS 3.2//EN"
      "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">

      <enterprise-beans>
      <message-driven>
      <ejb-name>MDBConsumer</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>topic/testTopic</destination-jndi-name>
      </message-driven>
      </enterprise-beans>


      ----------------------------------------------
      ejb-jar.xml

      <?xml version="1.0"?>
      <!DOCTYPE ejb-jar PUBLIC
      "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
      "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      <enterprise-beans>
      <message-driven>
      <ejb-name>MDBConsumer</ejb-name>
      <ejb-class>MDBConsumer</ejb-class>
      <message-selector></message-selector>
      <transaction-type>Bean</transaction-type>
      <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
      <message-driven-destination>
      <destination-type>javax.jms.Topic</destination-type>
      </message-driven-destination>
      </message-driven>
      </enterprise-beans>
      </ejb-jar>

      ----------------------------------------------------------
      MDB

      import javax.jms.*;
      import javax.ejb.*;

      public class MDBConsumer implements MessageDrivenBean, MessageListener{

      MessageDrivenContext context;

      public void setMessageDrivenContext (MessageDrivenContext context) {
      System.out.println("setMessageDrivenContext()");
      this.context = context;
      }

      public void ejbCreate() {
      System.out.println("ejbCreate()");

      }

      public void onMessage (Message msg) {
      try{
      System.out.println("onMessage()");
      System.out.println("Contenuto = "+((TextMessage)msg).getText());

      }catch(Exception e){
      System.out.println("Exception in onMessage()");
      e.printStackTrace();
      }
      }

      public void ejbRemove() {
      System.out.println("ejbRemove()");
      }
      }


      ----------------------------------------------------
      Publisher client



      import java.util.Hashtable;

      import javax.jms.JMSException;
      import javax.jms.TextMessage;
      import javax.jms.Topic;
      import javax.jms.TopicConnection;
      import javax.jms.TopicConnectionFactory;
      import javax.jms.TopicPublisher;
      import javax.jms.TopicSession;
      import javax.naming.Context;
      import javax.naming.InitialContext;



      public class TestPushQuote {

      public static void main(String[] args){
      try {

      Context context = null;
      TopicConnection topicConnection = null;
      TopicSession topicSession = null;
      Topic topic = null;
      TopicPublisher topicSender = null;
      TextMessage message = null;
      boolean esito = true;

      String destinationIP = "jnp://localhost:1099";
      Hashtable env = new Hashtable();
      env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      env.put(javax.naming.Context.PROVIDER_URL, destinationIP);

      try {
      context = new InitialContext(env);
      TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup("ConnectionFactory");
      topicConnection = topicFactory.createTopicConnection();
      topicSession = topicConnection.createTopicSession(false,
      javax.jms.Session.AUTO_ACKNOWLEDGE);
      topic = (Topic)context.lookup("topic/testTopic");
      topicSender = topicSession.createPublisher(topic);
      message = topicSession.createTextMessage();
      topicConnection.start();
      message.setText("Prova quote Edo");
      System.out.println("pubblico il messaggio .."+message.getText());
      topicSender.publish(topic, message);
      context.close();

      try {
      if(topicSender != null)topicSender.close();
      } catch (JMSException jme) {
      jme.printStackTrace();
      System.out.println(jme.toString());
      } finally {
      topicSender = null;
      }
      try {
      if(topicSession != null)topicSession.close();
      } catch (JMSException jme) {
      jme.printStackTrace();
      System.out.println(jme.toString());
      } finally {
      topicSession = null;
      }
      try {
      if(topicConnection != null)topicConnection.close();
      } catch (JMSException jme) {
      jme.printStackTrace();
      System.out.println(jme.toString());
      } finally {
      topicConnection = null;
      }



      } catch(Exception exc) {
      System.out.println(exc.toString());
      exc.printStackTrace();
      }



      } catch (Exception e) {
      System.out.println(e.toString());
      e.printStackTrace();

      }
      }
      }



      -----------------------------------------------------------------

      Any idea?

      Thanks in advance for your help.
      Regards