Monday, 10 January 2011

MDB Durable Subscribers

A durable subscriber is an MDB that will receive its messages even if it goes down. To make a MDB into a durable subscriber, you need to add a couple of lines to the ejb-jar.xml and weblogic-ejb-jar.xml.

The Ejb-Jar


<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
  <display-name>Event Logging Component</display-name>
  <enterprise-beans>
    <message-driven> 
      <ejb-name>EventLoggingMDB</ejb-name> 
            <ejb-class>uk.gov.hmrc.candi.service.ejb.EventLoggingMDB</ejb-class> 
      <transaction-type>Container</transaction-type>
          <message-destination-type>javax.jms.Topic</message-destination-type>
           <activation-config>
                <activation-config-property>
                    <activation-config-property-name>subscriptionDurability</activation-config-property-name>
                    <activation-config-property-value>Durable</activation-config-property-value>
                </activation-config-property>
           </activation-config>

       </message-driven> 
  </enterprise-beans> 
  <assembly-descriptor> 
    <container-transaction> 
      <method> 
        <ejb-name>EventLoggingMDB</ejb-name> 
        <method-name>*</method-name> 
      </method> 
      <trans-attribute>Required</trans-attribute> 
    </container-transaction> 
  </assembly-descriptor> 
</ejb-jar>



The Weblogic-Ejb-Jar


<?xml version="1.0" encoding="UTF-8" ?> 
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/10.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.bea.com/ns/weblogic/10.0 http://www.bea.com/ns/weblogic/10.0/weblogic-ejb-jar.xsd"> 
 
  <weblogic-enterprise-bean>
    <ejb-name>EventLoggingMDB</ejb-name>
     <message-driven-descriptor>
      <pool>
                <max-beans-in-free-pool>1</max-beans-in-free-pool>
              <initial-beans-in-free-pool>1</initial-beans-in-free-pool>
      </pool>
          <destination-jndi-name>EventTopic</destination-jndi-name> 
          <connection-factory-jndi-name>weblogic.jms.XAConnectionFactory</connection-factory-jndi-name> 
          <jms-client-id>EventLoggingClient</jms-client-id>
          <max-messages-in-transaction>1</max-messages-in-transaction>
     </message-driven-descriptor>
  </weblogic-enterprise-bean>
</weblogic-ejb-jar>