Search code examples
jmswildfly-8hornetqmessage-driven-bean

Generate Client ID on deploy


I have a WildFly cluster which should share all topic messages to different nodes and keep them if one node is offline.
For this case I need durable subscriper.

@MessageDriven(
    activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/Topic"),
        @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
        @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "anam123e"),
        @ActivationConfigProperty(propertyName = "clientID", propertyValue = "abcd"),
    }
)

I have noticed if I am using the same clientID the system is doing load-balancing. If I change the clientID or subscriptionName to an unique value it works.

So when to use a unique clientID and when subscriptionName?
My answer was, unique clientID per Node and subscriptionName per Thread on a Node.

Furthermore I want to generate a clientID based on the wildfly node name similar to:

@ActivationConfigProperty(propertyName = "clientID", propertyValue = "abcd-" + WildFly.getInstance().getNodeName()),

Is there a way to achieve it?


Solution

  • There is a real simple solution available: Property Replacement

    You need to enable it in the standalone.xml:

    <subsystem xmlns="urn:jboss:domain:ee:2.0">
        <annotation-property-replacement>true</annotation-property-replacement>
        ...
    </subsystem>
    

    And the new annotation can look like the following:

    @MessageDriven(
        activationConfig = {
            @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
            @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/Topic"),
            @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
            @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "aname"),
            @ActivationConfigProperty(propertyName = "clientID", propertyValue = "abcd-${jboss.node.name}"),
        }
    )