This post explains the steps to create and test a Message Driven Bean in WebSphere Commerce
Creating a Message Driven Bean
We will use WebSphereCommerceServerExtensionsData project to create our MDB.
In RAD, right click on the project WebSphereCommerceServerExtensionsData and go to New->Other-> Enterprise Bean as shown below and click Next
In the next window, select the radio box for Message-driven bean and enter the package, name bean name. Uncheck the ‘Generate an annotated bean class’ check box and click Finish.
MDB will be created in the WebSphereCommerceServerExtensionsData project. Open the MDB and inside the onMessage function and print the msg variable to System out.
Now we need to configure the MDB to listen on queues. We will come to this step later. First we need to create a local queue to send messages to this bean. Follow the next serious of steps to achieve this.
Login to the WAS admin console.
Go to ‘Service integration’ option and click on Buses link. You will be shown the below screen.
Click the ‘New’ button
In the below page, enter the Name as ‘MyBus’ and click OK. No need to change any other value.
You will be prompted to save the changes to master configuration. Do so by clicking the ‘Save’ link
Click the Save button to confirm Save. This process will be repeated for all changes made below.
Click the newly created ‘MyBus’. In the MyBus configuration page, you will see the ‘Bus members’ link in the right pane, click on that. You will be shown the below page.
Click ‘Add’ button.
In the new bus member configuration wizard, select the server radio box as shown below and click next.
In the next page, click Finish. You will be asked to save the changes in the master configuration file. Proceed as you have done earlier.
In the MyBus configuration page, select Destinations from the right pane and click on the new button.
In the new Destination configuration page, Select Queue radio box and click next
Give ‘MyQueue’ as the Queue name, click next
Ensure server1 is selected in the drop down and click next
In the final page just click finish.
Save the changes to the master configuration files when prompted.
Next step, go to the Resources->JMS Provider->Default Messaging section as shown below and click on the JMS Queue connection factory link from the right pane.
Click the ‘New’ button from the page shown.
In the resultant page, enter the values as shown in the screen shot and click ok. No need to change any other values in the page. You will be prompted to save the changes to master configuration, do the same.
Now click on the JMS Queue link from the right pane of Default configuration screen, you will see the below screen. Click the ‘New’ button.
In the resultant page, enter the values as shown in the screen shot and click ok. No need to change any other values in the page. Make sure that you select the correct bus and queue from the drop down. Please note that you need to first select the Bus from drop down to populate the Queue drop down. You will be prompted to save the changes to master configuration, do the same.
Now click on the JMS Activation specification link from the right pane of Default configuration screen, you will see the below screen. Click the ‘New’ button.
In the resultant page, enter the values as shown in the screen shot and click ok. No need to change any other values in the page. Make sure that you select the correct bus from the drop down. You will be prompted to save the changes to master configuration, do the same.
We have now completed all WAS configuration to create a Queue. Now we need to configure our MDB to listen on the Queue we created above.
To do that, open the Deployment descriptor of the WebSphereCommerceServerExtensionsData project and select the MDB from the Bean tab. You will see the below screen.
In the Activation Configuration section, click the ‘Add’ button. In the pop up window select values as shown below and click Finish
Now navigate to the WebSphere bindings section and select the JCA Adapter Radio and enter values as shown in the screen shot.
Now our MDB configuration is complete. MDB is now configured to listen to the newly created Queue.
Testing MDB
We will be testing the MDB using the Universal Test client provided by WebSphere. To enable the UTC, double click the server1 from the Server window. You will get the below screen. Check the ‘Enable universal test client’ check box.
Restart the server. Once server is started, right click the server and chose ‘Run Universal test client’ option. If you see any error, try to restart UTC from the same right click popup.
Once you run UTC, you will see the below screen.
Select the Send JMS Message option from left pane enter the details as shown below and click Send.
You will get a message sent message in the UTC.
In the System out log, you will see the msg printed as below from your MDB with the message you sent as the last line.