在Wildfly 10中,是否可以在standalone-full.xml中指定MDB查找属性,而不是在编译时在Java源代码中绑定?

时间:2017-11-05 17:42:25

标签: jms wildfly activemq-artemis jboss-mdb

在Wildfly 10中,我想将MDB的一些注释移动到相关的资源适配器。

根据Connect a pooled-connection-factory to a Remote Artemis Server 可以按如下方式对MDB进行注释(从引用的页面复制):

@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 {   
//       
}

有没有办法将查找决策从编译时延迟到调用时?我想指定属性的值" useJNDI"和"目的地"在我的standalone-full.xml

我尝试按如下方式注释MDB:

@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 {   
//       
}

然后配置" my-remote"在standalone-full.xml中,如下所示:

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

但是收到以下错误消息:

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'

是否必须在编译时指定查找属性?
如果我需要一个Wildfly实例使用jndi进行查找而另一个使用非JNDI名称,我是否真的需要创建两个注释略有不同的MDB?

1 个答案:

答案 0 :(得分:2)

&lt; pooled-connection-factory&gt;实际上只是HornetQ JCA资源适配器上的一个外观,以方便配置。除了在&lt; inbound-config&gt;中标识的一组有限的配置属性之外element(有关详细信息,请参阅架构),所有配置属性仅适用于出站适配器(即它们不适用于使用入站适配器的MDB)。 MDB使用的入站适配器实际上是要配置注释或部署描述符(即ejb-jar.xml)。

要实现您想要的功能,您可以将配置外部化到部署描述符,也可以在注释中使用系统属性替换。为了实现后者,你需要:

  1. 设置&lt; annotation-property-replacement&gt;在您的服务器配置中为true
  2. 设置&lt; jboss-descriptor-property-replacement&gt;在您的服务器配置中为true
  3. 在注释中使用$ {}语法,例如:

    @ActivationConfigProperty(propertyName = "destination", propertyValue = "${myDestinationProperty}")
    
  4. 在服务器配置中定义相应的系统属性,例如:

    <system-properties>
        <property name="myDestinationProperty" value="myQueue"/>
    </system-properties>
    
  5. 要清楚,在编译时没有对注释做任何事情。在MDB激活时,它们都会在部署时读取。