27 August 2013

Multiple MDBs with Durable Subscriptions on the Same Topic

In our scenario we have muliple JBoss servers that are connecting with a MDB to the same topic running on a central JBoss server with HornetQ.

First I tried to use MDBs with annotation based configuration. But this failed because I had to hard code the clientID and for every durable subscription the clientID must be unique.

To find the solution it took some time but it is quite simple. One has to use XML. There it is possible to use system properties. And because I didn't want to introduce a new system property I choosed an exisiting one: ${bind.address}

<message-driven>
  <ejb-name>CustomerUpdater</ejb-name>
  <ejb-class>com.prodega.proshop.integration.CustomerUpdater</ejb-class>
  <activation-config>
    <activation-config-property>
      <activation-config-property-name>
        destinationType
      </activation-config-property-name>
      <activation-config-property-value>
        javax.jms.Topic
      </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>
        destination
      </activation-config-property-name>
      <activation-config-property-value>
        /jms/CustomerTopic
      </activation-config-property-value>
    </activation-config-property>
    <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-property>
      <activation-config-property-name>
        clientID
      </activation-config-property-name>
      <activation-config-property-value>
        ${bind.address}
      </activation-config-property-value>
    </activation-config-property>
  </activation-config>
</message-driven>

Keine Kommentare: