0

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

有没有办法将查找决定从编译时间推迟到调用时间?我想在我的standalone-full.xml 中指定属性“useJNDI”和“destination”的值

我尝试如下注释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 {   
//       
}

然后在standalone-full.xml中配置“my-remote”如下:

<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 吗?

4

1 回答 1

3

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

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

  1. 在服务器配置中将 <annotation-property-replacement> 设置为 true
  2. 在服务器配置中将 <jboss-descriptor-property-replacement> 设置为 true
  3. 在注释中使用 ${} 语法,例如:

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

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

需要明确的是,在编译时没有对注释做任何事情。它们都是在部署时激活 MDB 时读取的。

于 2017-11-05T22:56:41.387 回答