• Post Reply Bookmark Topic Watch Topic
  • New Topic

container transaction and setRollbackOnly  RSS feed

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I have a persistent JMS Q running on WLS 6.1. I have a MessageDrivenBean with an onMessage method that reads the message off the q when it arrives. I am then writing the message to file.
Myquestions.
If I am running under a container managed transaction (which i set in the creation of the Qsession, and in the ejb-jar.xml) am I correct in thinking the container automatically commits the transaction if the message is written to file with no exceptions?
More importantly, if the message is not able to be written to file I want to rollback so the transaction can be started again and the message will be redelivered and therefore not lost.
I call setRollbackOnly on the messageDrivenContext, set up when the mdb is created by the continer. But then my server/jmsQ goes into an infinte loop trying to redeliver my message to the MDB . How can I break out of this loop?
I need to reconsume this message but only after the problem - why it cannot be written to file - has been fixed. Any ideas on how to do that?
I've tried testing to check if the messageDrivenContext has rollbackonly set, by calling getrollback only, but this fails to work!
Any help will be appreciated, my code is below:
*************************************************************
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the EJB specification, section 24.1.2 states that enterprise beans shouldn't attempt to write to files. Your code is doing this. What many people are doing are writing/using a log service like log4j. Your bean looks up the logger using JNDI and calls its methods to perform the logging. This way the file i/o occurs in another process. Weblogic has startup classes you can use for this. As far as the transaction is concerned, you could have the service post a status to another JMS queue when it has properly logged the message use this to fail/succeed the transaction. Some of the log utilities probably have better ways of handling this.
 
le taylom
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am intending to use Log4j to handle the logging of the message, but I was just using a simple write to file to make sure that I understood the specifics of the Message driven context.
However, I still don't. By using Log4j all I would be doing is using an inetrface to get a handle to the logging service and using its writer appender to write the message to a file. I understand that that would be happening in an other process, but the MDB will still be waiting for the return froim this process to confirm if the transaction has commited or not.
What are the Weblogic startup classes you mention?
Also I don't undersatnd what you mean when you say post the a status to another JMS queue, and use this to fail/succeed the transaction. How do I fail a transaction and thgen succeed it??
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!