@RequestScoped CDI injection into @MessageDriven bean

Deadly 提交于 2019-12-05 06:33:25

WRT the Request scope / context, the CDI spec in section 6.7.1 says that it will be active for a message driven bean implementing MessageListener. It is also destroyed after the delivery of the message, so you'll have a new instance for each message delivered. Further, section 6.7.3 states that the Application context is also active (as one would expect). Conversation and session scopes are not active.

I wonder if this will work. What kind of protocol do you intend to use with the MDB?

MDBs are nearly always invoked asynchronously (e.g. via JMS), so there's no notion of any active request when onMessage() is being called. Typically MDBs are also required to implement an interface matching the protocol they're listening to (e.g. for JMS the MDB needs to implement javax.jms.MessageListener).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!