Is it legal to inject a @Stateful into an MDB?
@Stateful
public class InteruptBean implements Interrupt {
....
}
@MessageDriven(...)
public class EchoTrigger implements MessageListener {
@EJB Interrupt interrupt;
....
}
Or better phrased: Can I use a stateful EJB to pass 开发者_StackOverflow社区state around in an asynchronous Event Driven Architecture?
Yes it does not make sense. Because stateful session beans are meant for processing multiple requests from same client so that they have client-actions oriented processing. In this case MDB will be beans clients. MDB supports single request model. A request comes to MDB (in form of message) and it is processed. So both types of beans don't match in processing model.
Yes, it's "legal", but it's nonsensical. MDBs instances are pooled like SLSBs. The MDB will become non-functional after the SFSB times out.
It might work to explicitly create the SFSB at some point, and then pass a reference to the SFSB in the messages being sent to drive the MDB.
精彩评论