Reputation: 2846
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?
Upvotes: 0
Views: 993
Reputation: 34973
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:
Use the ${} syntax in your annotations, e.g.:
@ActivationConfigProperty(propertyName = "destination", propertyValue = "${myDestinationProperty}")
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.
Upvotes: 3