How to stop Auto Acknowledgement

100 views
Skip to first unread message

Asgar Ahamed

unread,
Aug 11, 2016, 9:15:53 AM8/11/16
to Generic JMS JCA Resource Adapter for JBoss AS

Justin Bertram

unread,
Aug 11, 2016, 9:41:42 AM8/11/16
to Generic JMS JCA Resource Adapter for JBoss AS
The resource adapter you're using is not the same as the one supported on this forum (i.e. the Generic JMS JCA Resource Adapter for JBoss AS).  I know this because you're MDB is using activation configuration properties like "destinationJndiName" and "connectionFactoryJndiName" which we don't support.  There are other generic JMS JCA resource adapters out there so I imagine you're using one of those.

In any event, you cannot invoke javax.jms.Message.acknowledge() from within an MDB's onMessage().  If you want to control the acknowledgement of the message you'll need to use container-managed transactions which will either automatically commit the transaction (and acknowledge the message) once the MDB's onMessage completes or you can call setRollbackOnly() on the transaction to ensure the message does not get acknowledged (e.g. in case of some kind of failure).  This is all standard Java EE stuff.

Asgar Ahamed

unread,
Aug 11, 2016, 11:46:13 AM8/11/16
to Generic JMS JCA Resource Adapter for JBoss AS
Hello Justin,

Thank you very much for the information.
Could you please guide me to the correct/ relavent Group. It will be very much helpfull for me.

Justin Bertram

unread,
Aug 11, 2016, 11:52:17 AM8/11/16
to Generic JMS JCA Resource Adapter for JBoss AS
I won't be able to guide you to the correct group because I don't know what JCA RA you're using.  It could be an open source one or it could have been written by someone at your company.  There's no way for me to know.

In any event, the way Java EE works won't change.  No matter what JCA RA you use you won't be able to invoke javax.jms.Message.acknowledge() from within the MDB's onMessage().  You should control the acknowledgement as I already described.  Again, this is constant for all JCA RA implementations.

Asgar Ahamed

unread,
Aug 11, 2016, 11:52:46 AM8/11/16
to Generic JMS JCA Resource Adapter for JBoss AS
One more thing, I have tried as you said, but it gave me the below exception, (Looks Transaction Manager is not set CONTAINER

EJB 3.1 FR 13.6.1 Only beans with container-managed transaction demarcation can use setRollbackOnly.

My MDB looks like this




@TransactionManagement(value= TransactionManagementType.CONTAINER)
@TransactionAttribute(value= TransactionAttributeType.REQUIRED)
@ResourceAdapter("genericra.rar") 
@MessageDriven(mappedName = "NextWABMDB")


public class NextWABMDB implements MessageListener , MessageDrivenBean{
 
private MessageDrivenContext context;

private static final Logger LOG = Logger.getLogger(NextWABMDB.class);
private final MessageProcessor messageProcessor;
public NextWABMDB() {
this.messageProcessor = new MessageProcessor();
StatisticExceptionDetector statisticExceptionDetector = new StatisticExceptionDetector();
Thread.setDefaultUncaughtExceptionHandler(statisticExceptionDetector);
}
public void setMessageDrivenContext(MessageDrivenContext ctx){
      this.context = ctx;
  }
public void ejbRemove() {
    // implement the method just like a PreDestroy() method
  }  
 
@Override
public void onMessage(Message message){
UserTransaction utx= context.getUserTransaction();
try{
try {
            if (message instanceof TextMessage) {
                TextMessage msg = (TextMessage) message;
                this.messageProcessor.processNextWABXMLMessage(msg.getText());
                
                
                int i = 2/0;
            } else if (message instanceof ObjectMessage) {
            LOG.error("Received message was an ObjectMessage and will be ignored!");
            } else {
            LOG.error("Received message was not an Object- or TextMessage and will be ignored!");
            }
            
            
        } catch (JMSException e) {
        LOG.error("JMSException during onMessage.", e);
        }
catch (Throwable t) {
        LOG.error("Exception during onMessage New.", t);
        utx.setRollbackOnly();
        LOG.error("RollBack Done");
        throw new Exception(t.getMessage());
        }
}catch (Exception e) {
    LOG.error("Exception during onMessage.", e);
    }
}

}

Asgar Ahamed

unread,
Aug 11, 2016, 11:58:26 AM8/11/16
to Generic JMS JCA Resource Adapter for JBoss AS

Justin Bertram

unread,
Aug 11, 2016, 12:10:07 PM8/11/16
to Generic JMS JCA Resource Adapter for JBoss AS
I don't see the exception you're talking about, but I can tell you that what you're doing is wrong.  You cannot call javax.ejb.MessageDrivenContext.getUserTransaction() from an MDB using container-managed transactions.  The spec says this clearly, "...only session beans or message-driven beans with bean-managed transactions are allowed to invoke this method."  You simply need to call javax.ejb.MessageDrivenContext.setRollbackOnly() when you encounter a failure.  

Again, this is all basic Java EE stuff.  Perhaps you'd benefit from reading a Java EE tutorial.  There's lots of good resources out there.

Asgar Ahamed

unread,
Aug 12, 2016, 4:00:54 AM8/12/16
to Generic JMS JCA Resource Adapter for JBoss AS
I had two trails, so i had mess posting the code here sorry for that.
Trail 1:
Actually I have used BEAN managed with utx.rollback(). I see Acknowledge is sending even it executed utx.rollback(). this utx.rollback in BEAN managed will not stop Ack?

Trail 2:
with Container managed I execute only utx.setRollbackOnly();  It is some how not setting to Container Manager and gving me this error. (Still it is BEAN even i set like this @TransactionManagement(value= TransactionManagementType.CONTAINER) )

EJB 3.1 FR 13.6.1 Only beans with container-managed transaction demarcation can use setRollbackOnly.

So how can i force MDB to do Continer managed?. May be somewhere in Jboss or Resource Adaptor it is setting and am not able to overwrite it.

Justin Bertram

unread,
Aug 12, 2016, 8:28:45 AM8/12/16
to Generic JMS JCA Resource Adapter for JBoss AS
1)  Bean-managed transactions will not work for your purpose as the user transaction you start in the bean does not encapsulate the MDB's consumption of the message.  Therefore the ack for the message will be sent regardless of what happens with your user transaction.  You need to use container-managed transactions as I've already indicated.

2)  I already explained all this in my previous comment.  Please read it carefully, and I think you'll see the way forward.

Asgar Ahamed

unread,
Aug 30, 2016, 10:35:39 AM8/30/16
to Generic JMS JCA Resource Adapter for JBoss AS
Hi Justin,

Since we don't have the source for resource adaptor what we are using we have decided to use this resource adaptor.
I have alread did the Maven build of this resource adaptor. Got the rar file.
So how i have to integrate into my app along with setting to cotainer managed trasactions

Thanks a lot!

Regards
Syed

Justin Bertram

unread,
Aug 30, 2016, 10:43:57 AM8/30/16
to Generic JMS JCA Resource Adapter for JBoss AS
If you're using JBoss AS or Wildfly the basic instructions for integration are available in the documentation.  If you are using some other application server then you'd need to consult its documentation for further help.
Reply all
Reply to author
Forward
0 new messages