Is it possible to invoke a MessageDrivenBean remotely directly through a @Remote interface?

231 Views Asked by At

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?

1

There are 1 best solutions below

0
Justin Bertram On

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.