0

In Wildfly 10, I'd like to move some of the annotations of an MDB to the associated resource adapter.

According to Connect a pooled-connection-factory to a Remote Artemis Server one could annotate the MDB as follows (copied here from the referenced page):

@ResourceAdapter("remote-artemis")
@MessageDriven(name = "MyMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),  
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "myQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
})
public class MyMDB implements MessageListener {   
//       
}

Is there any way to defer the lookup decision from compile time to invocation time? I'd like to specify the values of the properties "useJNDI" and "destination" in my standalone-full.xml

I tried annotating the MDB as follows:

@ResourceAdapter("my-remote")
@MessageDriven(name = "MyMDB", activationConfig = {
    //try specifying the next 2 properties in the configuration file  
    //@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),  
    //@ActivationConfigProperty(propertyName = "destination", propertyValue = "myQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
})
public class MyMDB implements MessageListener {   
//       
}

And then configured "my-remote" in the standalone-full.xml as follows:

<pooled-connection-factory name="my-remote" entries="jms/RemoteCF" 
    connectors="batch-connector" consumer-window-size="0"
    useJNDI="false" destination="myQueue"
    user="user" password="password" />

But getting the following error message:

Message: WFLYCTL0376: Unexpected attribute 'useJNDI' encountered. Valid attributes are: 'entries, discovery-group, connectors, ha, client-failure-check-period, connection-ttl, call-timeout, call-failover-timeout, consumer-window-size, consumer-max-rate, confirmation-window-size, producer-window-size, producer-max-rate, protocol-manager-factory, compress-large-messages, cache-large-message-client, min-large-message-size, client-id, dups-ok-batch-size, transaction-batch-size, block-on-acknowledge, block-on-non-durable-send, block-on-durable-send, auto-group, pre-acknowledge, retry-interval, retry-interval-multiplier, max-retry-interval, reconnect-attempts, failover-on-initial-connection, connection-load-balancing-policy-class-name, use-global-pools, scheduled-thread-pool-max-size, thread-pool-max-size, group-id, transaction, user, password, min-pool-size, use-auto-recovery, max-pool-size, managed-connection-pool, enlistment-trace, initial-message-packet-size, initial-connect-attempts'

Do the lookup properties have to be specified at compile time?
If I have a need for one Wildfly instance to lookup using jndi and another using the non-JNDI name, do i really have to create two MDB's that are just annotated slightly differently?

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
inor
  • 2,781
  • 2
  • 32
  • 42
  • If your resort adapter is configured in the xml, you should not need any mdb annotations except @ResourceAdapter. – Nicholas Nov 05 '17 at 22:00

1 Answers1

3

The <pooled-connection-factory> is really just a facade on top of the HornetQ JCA resource adapter to facilitate configuration. Aside from a limited set of configuration properties identified in the <inbound-config> element (see the schema for more details), all the configuration properties apply only to the outbound adapter (i.e. they don't apply to MDBs which use the inbound adapter). The inbound adapter used by MDBs is really meant to be configured with annotations or with a deployment descriptor (i.e. ejb-jar.xml).

To achieve what you want you can externalize the configuration to the deployment descriptor or you can use system property substitution in your annotations. In order to implement the latter you'll need to:

  1. Set <annotation-property-replacement> to true in your server config
  2. Set <jboss-descriptor-property-replacement> to true in your server config
  3. Use the ${} syntax in your annotations, e.g.:

    @ActivationConfigProperty(propertyName = "destination", propertyValue = "${myDestinationProperty}")
    
  4. Define corresponding system properties in your server config, e.g.:

    <system-properties>
        <property name="myDestinationProperty" value="myQueue"/>
    </system-properties>
    

To be clear, nothing is done with the annotations at compile time. They are all read at deployment time when the MDB is activated.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • Thanks Justin. Btw, i also had to set jboss-descriptor-property-replacement to true in the server config. perhaps you can add it to your answer. Can the ${} be used only for obtaining the value of a property or can you also specify conditional expressions? – inor Nov 06 '17 at 09:24
  • 1
    You can specify a default value for a property using a colon (e.g. ${propertyName:defaultValue}) but the ${} syntax doesn't support any other kinds of expressions. – Justin Bertram Nov 06 '17 at 13:53