0 Replies Latest reply on May 29, 2003 2:54 AM by jboss_user_1

    JMS and EJB in transaction

    jboss_user_1 Newbie

      Hi,
      I have tried to involve a Topic in an ejb method that is under transaction.Even though I throw the Runtime Exception the message published is recieved by listener.It is not rolling back the messages.

      The code is following


      /**
      * @ejb.interface-method
      * view-type="remote"
      * @ejb:transaction type="Required"
      **/

      public String helloworld(String name) throws RemoteException{
      String hello=null;
      try{
      hello= "Hello from "+name+"Today is :"+new java.util.Date();
      InitialContext lContext = new InitialContext();
      TopicConnection conn=null;
      TopicConnectionFactory qfactory=(TopicConnectionFactory)lContext.lookup("ConnectionFactory");
      conn=qfactory.createTopicConnection();
      TopicSession session=conn.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
      Topic q=(Topic)lContext.lookup("topic/testTopic");
      TopicPublisher sender =session.createPublisher(q);
      TextMessage message=session.createTextMessage();
      for(int i=0;i<4;i++){
      message.setText("Dummy Message Created::"+i+new java.util.Date());
      sender.publish(q,message);
      System.out.println("Message Published"+new java.util.Date());
      }
      int i=0;
      if(i==0){
      System.out.println("Rolling Back");
      throw new Exception("RollBack Transaction");
      }

      }catch(Exception e){
      e.printStackTrace();

      throw new EJBException( "Remote exception occured while removing generator session bean: " + e.getMessage() );
      }

      return hello;

      }


      Any pointers