0

I am a newby with CDI and EJB and I've just created a jboss web application. Though, additionally, I also wanted this app to process rabbitmq messages. When processing these, I would like to do some persistence work, though, as I've been listening for rabbitmq messages from an application scoped bean that is started with the @Startup annotation, I've not been able to commit any transaction within this kind of scope, that is, as I am departing from the application scope, every bean that I will instatiate from this scope will be application scoped. When I try to perform em.getTransaction() and em.commit() the code blows up complaining that I cannot invoke getTransaction() under JTA transactions, and when I use User transactions, every operation seems to be put onto the same transaction until it finally is rolled back, or there errors complaining that there is a already a transaction underway...

Pedro Rolo
  • 28,273
  • 12
  • 60
  • 94
  • I have noticed that this question was voted for closing. Please do not do so and comment it instead, so I can improve it. Thank you. – Pedro Rolo Mar 16 '13 at 11:37
  • 2
    "not been able to commit any transaction within this kind of scope" what do you mean, did you get an error ? the transaction didn't start ? the transaction rollback ? additionally, I think posting some code can help us to understand the issue. – ben75 Mar 16 '13 at 21:29
  • I edited the question with further clarifications – Pedro Rolo Mar 17 '13 at 12:22
  • "the code blows up complaining something about JPA"... is it so difficult to post the error(s) trace ? Please provide more details otherwise your question wil be closed. – ben75 Mar 17 '13 at 13:55
  • My question is conceptual. It is not about fixing an exact bug, but rather about how to generate and persist events within CDI/EJB 3.1. I have tried several aproaches to solving this problem and I did not manage, so I ended up using a very ugly architectural-based patch and I do not have easy access to the traces I had in the past. I am making the question because I want to know what is the proper way to perform the mentioned task.IMHO Your behaviour in menacing to close the question and in trying to close it without even providing a comment goes against the objective and nature of this site. – Pedro Rolo Mar 17 '13 at 14:55
  • I didn't vote to close the question...yet. But in my opinion it's very difficult or even impossible to provide an answer to your question as it is formulated now. – ben75 Mar 17 '13 at 16:24

1 Answers1

1

CDI beans do not support transactions out of the box like EJBs do. So your options are to either:

  1. Upon receiving RabbitMQ messages, call some EJBs (directly or through observers) that will do the persistence work.
  2. Add transactions support to your existing CDI beans using one of the following - Apache DeltaSpike or Seam Persistence.

It is indeed quite hard to give you more details based on the info you provided. However, on the conceptual level, one of the approaches above would do the trick.

Also, the notion of event scope seems confusing. I would say you don't need it. One of the approaches above will do. Also, take a look at CDI events.

rdcrng
  • 3,415
  • 2
  • 18
  • 36