0
votes

I'm trying to send/produce JMS messages from a simple Stateless EJB. For this I'm using CDI to produce and inject the JMS resources (ConnectionFactory, Connection and Session). Exactly as described in the Weld doc - JavaEE integration, JMS enpoints.

The point is if I produce the JMS Session as trasacted the ,message is not sent (or commited) by my EJB. No error occurs.

CDI Resource producer:

@Produces
@ItemQualifier
public Session createJMSSession(@ItemQualifier Connection connection) throws JMSException {
    return connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
}

EJB JMS producer method:

public void pushItem(Item newItem) throws Exception {
    log.info("Sending " + newItem.getDescricao());
    log.info("Session Transacted? " + mineracaoSession.getTransacted());

    ObjectMessage message = session.createObjectMessage();

    message.setObject(newItem);
    producer.send(message);

    log.info("Message sent!");
}

If I change the Producer method to create non-transacted JMS Session the messages is sent (commited) normally.

I would like to understand why my EJB does not send/commit messages when the JMS session is transacted. All EJB methods is by default transacted, right?

1
Just curious, what EE version are you using? If you're on EE 7, you may want to use the new simplified JMS interfaces.John Ament
I'm using JavaEE 6 on JBossAS 7Rafael Soares - tuelho

1 Answers

0
votes

I found the answer in this JBoss Forum thread.

In sum if you want a transacted JMS Session you have to either control (commit/rollback) the tx by your self or use a JMS XAConnectionFactory. In my case I was using the default InVM ConnectionFactory which is not XA. So, in this case even using an EJB I had to invoke session.commit() explicitly. Or change my ConnectionFactory resource to the XA one.