0

I am currently learning the basics of EJB 2+. In the book Java EE 7 The Big Picture, it was mentioned:

Session beans are generally accessed through a remote interface (though, as we shall see, there are cases where a remote interface is not required), while message-driven beans have only a bean implementation class.

Based on the statement above, invoking a message-driven bean (MDB) just like invoking a remote session bean through a remote interface, whose server-side interface is done with @Remote annotation, seems to be impossible.

For instance, if there is a MDB on a remote EJB container:

@Remote
@MessageDriven(mappedName="jms/HelloQueue")
public class HelloMDB implements MessageListener {
    public void onMessage(Message msg) {
        //implementation
    }
}

Question: can the MDB mentioned above be invoked at all by a remote client directly and programmatically .e.g. through JNDI?

Rui
  • 3,454
  • 6
  • 37
  • 70
  • Did my answer address your question? If so, please mark it as correct to help others who may have this same question in the future. If not, please elaborate as to what is lacking. Thanks! – Justin Bertram Aug 30 '20 at 02:51

1 Answers1

1

No, an MDB cannot be invoked by a remote client directly as noted in this Java EE 7 tutorial from Oracle which states:

Client components do not locate message-driven beans and invoke methods directly on them.

If you want to invoke the MDB's onMessage then simply send a message to the destination where it's listening.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43