2 Replies Latest reply on Oct 8, 2002 10:43 AM by mantelus

    jms commit problem

    mantelus

      Hi there,

      i set up a new MessageQueue and wrote a simple client
      that sends messages to it. My message-driven bean recieves
      those messages.

      My problem is that upon exceptions those messages are
      still delivered, and i heard that you can send those
      messages in a way that the container sends them only
      when the transaction succeeds.

      when i use createQueueSession(true,Session.AUTO_ACKNOWLEDGE);

      my messages are only delivered if i manually trigger
      session.commit(); the container does not trigger it.
      the message is sent in a session ejb with the required
      transaction attribute.

      what could be wrong?

      thanks a lot,
      Hannes

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

      String QUEUE_NAME = "queue/MantelusQ";
      String CONNECTION_FACTORY = "java:/XAConnectionFactory";
      QueueSender sender;
      QueueSession session;
      InitialContext ctx = new InitialContext();
      // Lookup a JMS connection factory
      QueueConnectionFactory conFactory =
      (QueueConnectionFactory) ctx.lookup(CONNECTION_FACTORY);
      // Create a JMS connection
      QueueConnection connection = conFactory.createQueueConnection();
      // Create a JMS session object
      session = connection.createQueueSession(/* transacted */true, Session.AUTO_ACKNOWLEDGE);
      // Lookup a JMS queue
      Queue chatQueue = (Queue) ctx.lookup(QUEUE_NAME);
      // Create a JMS sender
      sender = session.createSender(chatQueue);
      MapMessage message = session.createMapMessage();
      message.setString("Hello","World");
      sender.send(message);

      // sender.close();
      // session.commit();
      session.close();
      // connection.close();

      // if(0==0)
      // throw new EJBException("bla");

      return ";-)";