问题
In our project, we are are using an MDB that listens for a message on a specific queue. It is defined as an annotation.
Example:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "20")})
.
In order to change the value of the maxSessions, the code has to be compiled everytime. Even if i configure it in ejb-jar.xml instead of as an annotation , i need to compile the code and generate EAR file.
Is there a way to make it user configurable(read from properties file) so that the recompilation of code is not required and by just changing the maxSession value to "30" and restarting the jboss, it should be working.
Kindly help.
Reference Code:
@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
{
-----------
}
回答1:
I started to write a gist about Wildfly8 and Websphere MQ integration, allowing to configure and maintain environment contextual configuration for MDB or JMS messages producers.
Basically, I had to declare a jboss-ejb3.xml custom deployment descriptor in my application which use system properties for contextual configuration used by my MDB.
System-properties are configured in wildfly standalone-full.xml file, under system-properties element. So not in a property file, but to my view standalone-full.xml configuration is a good location for such configuration.
Here is the link : https://gist.github.com/remibantos/33c366803f189db9b225
回答2:
There is an easy way in Wildfly (I've used it for Wildfly 11).
- Enable property replacement in annotation by updating "ee" subsystem in standalon-xx.xml or domain.xml
<subsystem xmlns="urn:jboss:domain:ee:4.0">
...
<annotation-property-replacement>true</annotation-property-replacement>
...
</subsystem>
Define the System Properties, in standalon-xx.xml or domain.xml
<system-properties>
<property name="property.maxsessions" value="50"/> </system-properties>
Or your own properties file using -P myconfigured.properties
, while starting wildfly
Or via command line while starting wildfly -Dproperty=value
Modify MDB annotation
@ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "${property.maxsessions}")
Reference: https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/developing_ejb_applications/#message_driven_beans-1
来源:https://stackoverflow.com/questions/34030422/how-to-make-mdb-activation-spec-contextual-properties-configurable