A message driven bean is a form of enterprise bean, which is invoke by EJB container when it receives a message from queue or theme. Message driven bean is a stateless bean and is used to do task asynchronously.
To display use of message driven bean, we will make use of EJB-persistence section and we need to do the following responsibilities −
Create a file named jbossmq-destinations-service.xml if not exist in <Jobs Installation Folder> > server > default > deploy folder.
Here we are creating a queue named Book Queue −
When you begin the Jobs, you will see a similar entry in jobs log.
LibraryMessageBean is annotating with @Message Driven annotation to mark it as message driven bean.
Construct the EjbComponent scheme and deploy it on Jobs. After building and deploying the EJB element, we need a client to send a message to jobs queue.
Let us generate a test EJB application to test Message Driven Bean.
|1||Create a project with a nameEjbComponentunder a packagecom.wisdomjobs.entityas explained in theEJB - Create Applicationchapter. You can also use the project created inEJB - Create Applicationchapter as such for this chapter to understand EJB persistence concepts.|
|2||CreateBook.javaunder packagecom.wisdomjobs.entityas created inEJB-Persistencechapter.|
|3||CreateLibraryPersistentBean.javaandLibraryPersistentBeanRemoteas created inEJB-Persistencechapter.|
|4||Createjboss-ds.xmlinEjbComponent > setupfolder andpersistence.xmlinEjbComponent > src > conffolder. These folders can be seen in files tab in Netbeans as created inEJB-Persistencechapter.|
|5||CreateLibraryMessageBean.javaunder a packagecom.wisdomjobs.messagebeanand modify it as shown below.|
|6||CreateBookQueuequeue in Jboss as described above.|
|7||Clean and Build the application to make sure business logic is working as per the requirements.|
|8||Finally, deploy the application in the form of jar file on JBoss Application Server. JBoss Application server will get started automatically if it is not started yet.|
|9||Now create the EJB client, a console based application in the same way as explained in theEJB - Create Applicationchapter under topicCreate Client to access EJB. Modify it as shown below.|
EJBTester performs the following tasks −
Locate EJBTester.java in assignment explorer. Right click on EJBTester class and choose run file.
Prove the following output in Net beans console –
The output exposed above states that our Message driven bean is receipt the message and storing the book in persistent storage and books are retrieved from the folder.
EJB(Enterprise JavaBeans) Related Interview Questions
|J2EE Interview Questions||Core Java Interview Questions|
|JDBC Interview Questions||JSP Interview Questions|
|Android Interview Questions||JMS(Java Message Service) Interview Questions|
|JavaServer Faces (JSF) Interview Questions||Java collections framework Interview Questions|
|Java 8 Interview Questions||Java Collections Interview Questions|
|Java Exception Handling Interview Questions||Java Concurrency Interview Questions|
|Java Serialization Interview Questions||Java Programmer Interview Questions|
|Java Inheritance Interview Questions||Java IO Interview Questions|
|Object Oriented Programming in PHP Interview Questions|
Ejb(enterprise Javabeans) Tutorial
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.