简体   繁体   中英

JMS - Redelivery flow in a queue

Configuration

I´m using EJB 3 in OC4J 10.1.3.x

The problem

I create a queue producer with CLIENT_ACKNOWLEDGE orientation, like:

    queueConnection = queueConnectionFactory.createQueueConnection();
    queueSession = queueConnection.createQueueSession(false,
            Session.CLIENT_ACKNOWLEDGE);
    queueSender = queueSession.createSender(queue);

    ObjectMessage objMessage = queueSession.createObjectMessage();
    Mail data = new Mail();
    data.setMessage("Some random message.");
    objMessage.setObject(data);
    queueSender.send(objMessage);

What I understand of it is that the consumer should handle the ack of the message, in other words, if the consumer DO NOT call the message.acknowledge() method, so the message should be redelivery. Is it right?

What is happen is, when my MDB just read the message (by the listener onMessage ) that message just get off from the queue (independent if I call or not the message.acknowledge() method).

   public void onMessage(Message message) {
            try {
                if (message instanceof ObjectMessage) {
                    ObjectMessage objectMessage = (ObjectMessage) message;
                    Mail mail = (Mail) objectMessage.getObject();
                    System.out.println(mail.getMessage());
                    throw new RuntimeException("Error");
                }
            } catch (JMSException e) {
            }

What I am doing wrong?

Well, I did lots of research about it and I found that the container usually ignores the client control on session creation. In this case: queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); So, if you need to handle message process in a MDB with acknowledge or not you need to work with an EJB transaction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM