I have a java code that contains the @ResourceAdapter annotation in my EAR that I deploy in Wildfly:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "useJndi", propertyValue = "true"),
@ActivationConfigProperty(propertyName = "destination",
propertyValue = "java:/jms/queue/myqueue"),
})
@ResourceAdapter("my-resource-adapter")
public class MyMessageListener implements MessageListener {
@Override
public void onMessage (Message message) {
}
}
I add the resource adapter via CLI:
/subsystem=resource-adapters/resource-adapter=my-resource-adapter:add(archive=activemq-rar-5.18.2.rar,transaction-support=XATransaction)
/subsystem=resource-adapters/resource-adapter=my-resource-adapter/config-properties=ServerUrl:add(value=<url>)
/subsystem=resource-adapters/resource-adapter=my-resource-adapter/connection-definitions=my-resource-adapter.connection:add(<connection definitions here>)
/subsystem=resource-adapters/resource-adapter=my-resource-adapter/admin-objects=<admin objects here>
/subsystem=resource-adapters/resource-adapter=my-resource-adapter:activate
Everything works fine. Now, I want to introduce a boolean property whether to use and deploy the ActiveMQ resource adapter or not. Initially, I did this by having an if statement:
set use_resource_adapter=${use_resource_adapter}
if (outcome == "success" && result == "true") of :resolve-expression(expression=$use_resource_adapter)
/subsystem=resource-adapters/resource-adapter=my-resource-adapter:add(archive=activemq-rar-5.18.2.rar,transaction-support=XATransaction)
/subsystem=resource-adapters/resource-adapter=my-resource-adapter/config-properties=ServerUrl:add(value=<url>)
/subsystem=resource-adapters/resource-adapter=my-resource-adapter/connection-definitions=my-resource-adapter.connection:add(<connection definitions here>)
/subsystem=resource-adapters/resource-adapter=my-resource-adapter/admin-objects=<admin objects here>
/subsystem=resource-adapters/resource-adapter=my-resource-adapter:activate
end-if
But if the parameter is false, I receive this error when deploying the EAR file:
{"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"WFLYCTL0412: Required services that are not installed:" => ["jboss.ra.my-resource-adapter"],"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.deployment.subunit.\"myear.ear\".\"myear.jar\".component.MyMessageListener.CREATE is missing [jboss.ra.my-resource-adapter]"]}}}
Is there a way for the @ResourceAdapter annotation to not fail when the resource-adapter is not configured/ activated?
Thanks!
Expected Result: If the java code is left as it is and no resource adapter was added via CLI, then the EAR should still deploy and not cause the WFLYCTL0062 error
to disable the
@ResourceAdapterannotation in Wildfly when the resource adapter is not configured or activated, you can make use of the@Resourceannotation instead.here's how you can modify your code:
by using the
@Resourceannotation with thelookupattribute, you can directly inject the required resource (in this case, the JMS queue) without explicitly specifying the resource adapter.this way, if the resource adapter is not configured or activated, the deployment of the EAR file will not fail. The
@Resourceannotation will simply leave the injected resource asnullin that case.note that you will need to remove the
@ResourceAdapter("my-resource-adapter")annotation from your code.by using this approach, you can control the usage of the resource adapter based on your boolean property (
use_resource_adapter). If the property is set totrue, you can configure and activate the resource adapter via CLI as before. If the property is set tofalse, you can omit the resource adapter configuration and the deployment will still succeed without any errors.