Showing posts with label MDB. Show all posts
Showing posts with label MDB. Show all posts

Friday, May 3, 2013

MDB throttling using Work Managers in Weblogic


A JMS Message Burst can result in a lot of threads created to process these messages. Because of this other applications/processes might not have threads to run or exhaust on data source connections etc..

One way to solve this is to use work Managers.
Work managers can be created globally or in the application scope.
1. Global Scoped Work Managers: These are accessible by every application running in the targeted server. These are created in the weblogic console
2. Application Scoped: These are defined in the application and are only available to the application.  They can be defined in weblogic-application.xml(the ear) or weblogic-ejb-jar.xml(module) or weblogic.xml(particular web application).

if you are defining in this in  weblogic-ejb-jar.xml
<weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"
                  xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar">
<weblogic-enterprise-bean>
<ejb-name>MyEJBBean</ejb-name>
  <message-driven-descriptor>
    <destination-jndi-name>jms/dq</destination-jndi-name>
    <connection-factory-jndi-name>jms/tqcf</connection-factory-jndi-name>
  </message-driven-descriptor>
  <dispatch-policy>WM1</dispatch-policy>
</weblogic-enterprise-bean>
<work-manager>
  <name>WM1</name>
  <min-threads-constraint>
    <name>wm2_mintc1</name>
    <count>0</count>
  </min-threads-constraint>
  <max-threads-constraint>
    <name>wm2_maxtc1</name>
    <count>3</count>
  </max-threads-constraint>
</work-manager>
</weblogic-ejb-jar>

You can also have the workmanager defined in the weblogic.xml or in weblogic-application.xml by having xml like this. and the MDB will refer the work manager in <dispatch-policy> tag.
work-manager>
  <name>WM1</name>
  <min-threads-constraint>
    <name>wm2_mintc1</name>
    <count>0</count>
  </min-threads-constraint>
  <max-threads-constraint>
    <name>wm2_maxtc1</name>
    <count>3</count>
  </max-threads-constraint>
</work-manager>

If you want to to define a global scoped work manager. You can do it in the weblogic console as below


image

If you want to throttle MDB threads by Database connection Pool Size. You can change the max constraint to have  pool-name tag instead of count tag. You fill the data source name here and not the jndi
work-manager>
  <name>WM1</name>
  <min-threads-constraint>
    <name>wm2_mintc1</name>
    <count>0</count>
  </min-threads-constraint>
  <max-threads-constraint>
    <name>wm2_maxtc1</name>
   <pool-name>OracleDS</pool-name>  </max-threads-constraint>
</work-manager>