Hi,
Many times we want to suspend or resume the MDBs due to some production maintenance. In this case rather than using the AdminConsole we can use WLSTScript to automate the Production maintenance. The best thing to suspend the Message Processing (Message Consumption) is to untarget the MDB Application. Suppose if the MDB is targeted to WebLogic Server “TestServerOne” then using WLST script we need to just untarget the MDB Application. So in this case the Incoming Messages will be still stored in the JMS Queue but they will not be processed by the MDB because the MDBs are not targeted to any Server.
As soon as the Maintenance completes we can again Target the MDB to the WebLogic Server so that the MDB will again start processing the JMS Messages present inside the JMS Queue. Here is a Simple Demonstration of it:
Step1). Create an MDB application as described in the following Link: http://middlewaremagic.com/weblogic/?p=1987
Step2). Now Create a Jar file of your MDB then place it inside an EAR file with the following kind of “MDB_Apps_Ear/META-INF/application.xml” file.
<?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4"> <description>Suspending_Resuming MDB Example</description> <display-name>Suspending_Resuming MDB Example</display-name> <module> <ejb>mdb30.jar</ejb> </module> </application>
Step3). Now Deploy the EAR application to some Server like AdminServer ..
Step4). Start Sending some Messages using the Program “QueueSend.java” in Step6) as mentioned in the Above Link: http://middlewaremagic.com/weblogic/?p=1987
Step5). Now write the following WLST Script somewhere in your FileSystem to Untarget your Deployed EAR application so that it will stop Consuming JMS Messages which are coming to the JMS Queue.
earAppName="MDB_Apps_Ear" currentTargetOfEAR="AdminServer" connect('weblogic','weblogic','t3://localhost:7001') edit() startEdit() ls() cd('/AppDeployments/' + earAppName) ls() cmo.removeTarget(getMBean('/Servers/' + currentTargetOfEAR)) save() activate()
Step6). Now you can write the Following WLST Script to make your MDBs again ready to start Consuming JMS Messages from the JMS Queue by Targeting them back to the WebLogic Server back.
earAppName="MDB_Apps_Ear" currentTargetOfEAR="AdminServer" connect('weblogic','weblogic','t3://localhost:7001') edit() startEdit() ls() cd('/AppDeployments/' + earAppName) ls() cmo.addTarget(getMBean('/Servers/' + currentTargetOfEAR)) save() activate()
NOTE:Suspending One individual MDB from an EAR file is not possible so if your EAR application Contains multiple MDBs then you will have to suspend all the MDBs present in that EAR like above.
Or Whatever MDB you think is requires regular Suspension or Resuming process make them Separate from the Original EAR.
.
.
Thanks
Jay SenSharma
January 10th, 2011 on 4:58 pm
You can also “Pause” consumption on a specific JMS destination rather than un-deploy – I haven’t done this using WLST but have used it through the console. I’m still on WLS8.1, so limited 10+ scripting!
Also – rather than making MDB’s in a separate EAR file, we have used a custom classloader hierarchy so that we can stop and start individual MDB’s in the same EAR file.
Pete
January 10th, 2011 on 7:35 pm
Hi Peteinman,
The above post we developed for a Scenario where An EAR application was having say 5 MDBs and an Administrator wanted to just suspend one of the MDB which was part of an EAR application so that that particular MDB will stop listening the Messages present in the JMS queue.
In WebLogic 9 and above AdminConsole i didnot find an option to just suspend one of the MDB so i used the above idea mentioned in the following post…http://middlewaremagic.com/weblogic/?p=5099
.
.
Keep Sharing 🙂
Thanks
Jay SenSharma
January 19th, 2011 on 1:51 am
Hi
Do we need a server bounce for target and un-targetting the application, like in deployment and un-deployment ?
What is the difference between un-targetting an application and un-deploying an application, is it safe to use this in the Production environments, would there be any effects ?
January 19th, 2011 on 1:29 pm
Hi Santosh,
Usually To undeploy and deploy an application we do not require thew Server restart. But some applications are not developed according to the standards and leaves many dependencies outside the Application Archieve in those cases we require server restart. But if the application has all the required Jars inside it’s archive only then we do not require any restart for deployment/Undeployment.
Un-targetting is different from the Undeployment as the application still be there in the Server in “NEW” state when we un-target an application which is little light weight operation compared to Undeployment … but in case of undeployment the application archive and it’s temporary files are deleted from the server.
In production environment for some applications like SLSB/SFSB/WebApplications it is not recommended to untarget an application because the Clients Data will be lost and the application will not be available for user access…. But in case applications which contains MDBs it is OK to untarget the application based on requirement …Because the MDBs are implemented to maintain Asynchronous behavior. Means even if we untarget the MDB based application the Clients will not be impacted because their JMS Messages will be stored in the JMS Queue until the MDB is available….As soon as the MDB will be targeted back it will start consuming the Messages from the JMS Queue and will perform required processing on the Messages.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
January 21st, 2011 on 12:48 am
Hi Jay,
Thank you for a detailed explanation. I was looking further for any other option other than suspending the whole application (the MDB in my application is also a part of the EAR). I understand that you have explained that it is not possible to suspend or resume a MDB which is part of an EAR, but I have come across a few more articles stating that it is different in WebLogic 10.x when compared to older versions. So I tried out the below option
I came across MessageDrivenControlEJBRuntime under the domainRuntime. I tried to use the suspendMDBs option it is returning a Boolean value 1 but I don’t see any difference in the state of the MDB on the console.
Please advise.
Thanks
Santosh