users@glassfish.java.net

RE: Setting AcknowledgeMode on a Session (Direct)

From: Robert Weeks <RWeeks_at_ext-inc.com>
Date: Wed, 23 Mar 2011 05:39:01 -0700

Hey Nigel -

Thank you very much for the reply. This is great information.


Robert Weeks
Senior Software Developer
EXTENSION, INC.
Email: rweeks_at_ext-inc.com
Office: 260-797-0200 x4228
General: 877-207-3753
www.OpenTheRedBox.com

Download the FREE EXTENSION Mobile App for iPhone and iPod Touch
http://www.opentheredbox.com/iPhone_appDemo.php

Email us at demo_at_ext-inc.com <mailto:demo_at_ext-inc.com> to pre-schedule a LIVE demo for our HealthAlert for Nurses solution at the AONE Conference in San Diego. Visit us at booth #118



________________________________________
From: Nigel Deakin [nigel.deakin_at_oracle.com]
Sent: Wednesday, March 23, 2011 8:13 AM
To: users_at_glassfish.java.net
Subject: Re: Setting AcknowledgeMode on a Session (Direct)

Good question. The reason for this behaviour is that the arguments to createSession() are handled differently in a Java
EE environment than in a simple JMS client.

Please look at the EJB 3.1 Spec, section 13.3.5 "Use of JMS APIs in Transactions" (which also applies to web applications):

This states: "Because the container manages the transactional enlistment of JMS sessions on behalf of a bean, the
parameters of the createSession(boolean transacted, int acknowledgeMode), createQueueSession(boolean transacted, int
acknowledgeMode) and createTopicSession(boolean transacted, int acknowledgeMode) methods are ignored. It is recommended
that the Bean Provider specify that a session is transacted, but provide 0 for the value of the acknowledgment mode."

It continues: "The Bean Provider should not use the JMS acknowledge method either within a transaction or within an
unspecified transaction context. Message acknowledgment in an unspecified transaction context is handled by the container."

So client acknowledgement is not allowed. Because of this the argument Session.CLIENT_ACKNOWLEDGE is ignored. If there's
no transaction then the message will be automatically acknowleged (AUTO_ACKNOWLEDGE), or if there a transaction then the
message will be acknowledged when the transaction is committed.

Nigel


On 22/03/2011 20:10, Robert Weeks wrote:
> Hello -
>
> Using GF3.1, when trying to set an AcknowledgeMode on a session, it never seems to stick.
>
> I am pulling a ConnectionFactory from jndi for us:
>
> create-jms-resource --restype javax.jms.QueueConnectionFactory --description "QueueConnectionFactory" jms/ExtQueueConnectionFactory
>
> When I get this back - it reports as: com.sun.messaging.jms.ra.DirectConnectionFactory
>
> Then - trying to create a session with CLIENT_ACKNOWLEDGE and then immediately testing it:
>
>
> Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
> This results in the object:
> >> SESSION: com.sun.messaging.jms.ra.DirectTransactionManagedSession_at_967e07
>
>
> Checking transacted (log.error(">> Are we transacted? " + session.getTransacted())) we get:
> >> Are we transacted? false
>
> Then immediately trying to get what the acknowledgeMode is on the session we just created:
> session.getAcknowledgeMode(): 1 (AUTO_ACKNOWLEDGE)
>
> If I write an app and connect to the message queue non-direct (via mq://127.0.0.1:7676), this works fine - but that is not returning the DirectConnectionFactory nor the DirectConnection - and the session is slightly different too.
>
> It appears that the session is not transacted (which is right) - but I cannot get the setting of the ack mode to be correct here.
>
> Is there something I am missing?
>
> Thanks for any information.
>