Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Message.acknowledge()

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Frits' notes, p.37, for container managed transaction,
it is not allowed to use Message.acknowledge() either within a transaction or within an unspecified transaction context.


Question 1: 'either within a transaction or within an unspecified transaction context' means regardless the bean is executing a transaction or not, the bean should never invoke Message.acknowledge() method in onMessage(), lifecycle callback interceptors, timer callback interceptors, business method interceptors or inside business methods?

Question 2: MDB should not invoke Message.acknowledge() because the EJB container will acknowledge the receipt of the message to the messaging provider. In the other words, the container will acknowledge the message on behalf of the MDB. Is this the reason why Message.acknowledge() is not allowed in MDB?

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 1: 'either within a transaction or within an unspecified transaction context' means regardless the bean is executing a transaction or not, the bean should never invoke Message.acknowledge() method in onMessage(), lifecycle callback interceptors, timer callback interceptors, business method interceptors or inside business methods?

Be careful: an unspecified transaction context is not the same as no transaction context (check ejb specs 13.6.5 Handling of Methods that Run with "an unspecified transaction context"). But generally spoken: don't use this method when you have a MDB.

Question 2: MDB should not invoke Message.acknowledge() because the EJB container will acknowledge the receipt of the message to the messaging provider. In the other words, the container will acknowledge the message on behalf of the MDB. Is this the reason why Message.acknowledge() is not allowed in MDB?

Exactly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic