2

I'd like to be able to do a health check on a deployed Message-Driven Bean in Production. My initial idea was to add a health() method ensuring that the JMS Queue (for reading) and the Database (for writing) are both available, and then expose this health method as a REST API. Unfortunately as a MDB isn't injectable like the other types of EJBs I cannot get a reference to it from my REST controller...

Is there a way to expose a message-driven bean's methods through a REST API ? Or any other way to achieve my initial goal ?

EDIT

A little precision : I don't want to just check that the resources are available, but also that the EJB can communicate with them (by pinging them from inside the EJB instance). This would not only validate that the resources are available (which could indeed be done some other way), but more importantly for me also that the resources bindings are valid and that the resources injection is working.

Thomas Naskali
  • 551
  • 5
  • 19
  • Your application server will normally manage the pool of MDB instances and DB connections, adding a check to an MDB wouldn't really help as you'll only be checking one instance (and tieing up the resource while you're doing it). Most app servers will provide a JMX interface for monitoring these resources, but the available information will depend on the server. – Nick Wilson Jun 11 '18 at 14:16
  • @NickWilson I would argue that checking one instance would be enough to validate all instances. If I can access (ping) the resources from one EJB, then there's a very good chance they're all be able to do so because the bindings and injection are OK. I have edited my question to be more explicit about what it is I want to validate and why I think I need to do it from inside the EJB. – Thomas Naskali Jun 12 '18 at 05:38

1 Answers1

1

I think it's not possible the way you want to have it. The reason is, that unlike other EJBs, a MDB solely acts upon arrival of a message and not by any other call to it.

But you may do it the other way round and inject some class into the MDB which you call on any message you receive. That way you'd have a constant "I'm alive" ping, provided that you get messages continuously.

Other than that your only chance is to use the mechanisms of your container which usually can provide some information about its deployed and running components which you may query.

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96