如何使 MDB 激活规范上下文属性可配置?

Hel*_*llo 2 java jms jboss-mdb wildfly

在我们的项目中,我们正在使用一个 MDB 来侦听特定队列上的消息。它被定义为注释。

例子:

@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "20")})
Run Code Online (Sandbox Code Playgroud)

.

为了更改 maxSessions 的值,每次都必须编译代码。即使我在 ejb-jar.xml 中配置它而不是作为注释,我也需要编译代码并生成 EAR 文件。

有没有办法让它用户可配置(从属性文件中读取),以便不需要重新编译代码,只需将 maxSession 值更改为“30”并重新启动 jboss,它应该可以工作。

请帮忙。

参考代码:

@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "ABCQueue"),
@ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "20"),    @ActivationConfigProperty(propertyName="maxMessagesPerSessions",propertyValue="15")})
public class ABCMDB implements MessageListener
{
   ----------- 
}
Run Code Online (Sandbox Code Playgroud)

vij*_*nki 5

Wildfly 中有一个简单的方法(我已经将它用于 Wildfly 11)。

  1. 通过更新standalon-xx.xml 或domain.xml 中的“ee”子系统来启用注释中的属性替换

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

  1. 在standalon-xx.xml 或domain.xml 中定义系统属性

    <system-properties>
    <property name="property.maxsessions" value="50"/> </system-properties>

或者你自己的属性文件使用-P myconfigured.properties, 同时启动 wildfly

或者在启动wildfly时通过命令行 -Dproperty=value

  1. 修改 MDB 注释

    @ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "${property.maxsessions}")

参考:https : //access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/developing_ejb_applications/#message_driven_beans-1