JMS transaction exception thrown in a transactionless session

Hello, I have a problem with my jms code when I try to send more than 1000 messages in MDB. The following code:

@Stateless(mappedName = "RequestProcessingQueue")
public class RequestProcessingQueue {
private static final Logger logger = Logger.getLogger(RequestProcessingQueue.class);

@Resource(mappedName = "jmsRequestsFactory")
private ConnectionFactory connectionFactory;

@Resource(mappedName = "jmsRequestsDestination")
private Queue queue;

public void add(String participant, String password, List<Long> documents) throws JmsAppException {

    try {
        logger.debug("requests to process " + documents);
        Connection connecton = connectionFactory.createConnection();
        connecton.start();
        Session session = connecton.createSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender sender = (QueueSender) session.createProducer(queue);
        Message msg = msg = session.createMessage();
        msg.setStringProperty("participant", participant);
        msg.setStringProperty("password", password);

        for (Long id : documents) {
            msg.setLongProperty("request", id);
            sender.send(msg);
        }

        sender.close();
        session.close();
        connecton.close();
    } catch (JMSException e) {
        throw new JmsAppException(e);
    } catch (Throwable e) {
        throw new JmsAppException("Fatal error occured while sending  request to be processed", e);
    }
}

}

throws

 MQJMSRA_DS4001: JMSServiceException on send message:sendMessage: Sending message failed. Connection ID: 2979509408914231552 com.sun.messaging.jms.ra.DirectSession._sendMessage(DirectSession.java:1844) / sendMessage: Sending message failed. Connection ID: 2979509408914231552 com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService.sendMessage(IMQDirectService.java:1955) / transaction failed: [B4303]: The maximum number of messages [1 000] that the producer can process in a single transaction (TID=2979509408914244096) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. com.sun.messaging.jmq.jmsserver.data.handlers.DataHandler.routeMessage(DataHandler.java:467)'}
    at jms.example.RequestProcessingQueue.add(RequestProcessingQueue.java:48)

I don't understand why cus, when I create a session, pass false as the first parameter indicating that the session is not transactional.

+4
source share
1 answer

, JMS API , EJB. EJB JavaDoc, javax.jms.Connection.createSession(boolean transacted, int confirmMode).

( Java 7):

@TransactionAttribute(TransactionAttributeType.NOTSUPPORTED)
public void add(String participant, String password, List<Long> documents) throws OgnivoException {

    try (Connection connection = connectionFactory.createConnection();
         Session session = connection.createSession();
         // session.start() not required
         MessageProducer sender = session.createProducer(queue)) {
        logger.debug("requests to process " + documents);

        for (Long id : documents) {
            Message msg = msg = session.createMessage();
            msg.setStringProperty("participant", participant);
            msg.setStringProperty("password", password);
            msg.setLongProperty("request", id);
            sender.send(msg);
        }

    } catch (JMSException e) {
        throw new JmsAppException(e);
    }
    // Don't catch throwable because it hides bugs
}

, EJB , . , javadoc javax.jms.Connection.createSession() , , .

+2

Source: https://habr.com/ru/post/1659157/


All Articles