I want to terminate a @MessageDriven
AMQ consumer from an EAR project’s code programmatically. The code of termination is like this:
private void stopJmsDelivery() {
log.info("Stopping jms delivery");
// this consumer can be stopped normally
stopJmsDelivery("jboss.as:deployment=main.ear,subdeployment=somehow-bizarre.jar,subsystem=ejb3,message-driven-bean=UnknownConsumer");
...
// this one throws exception
stopJmsDelivery("jboss.as:deployment=another.war,subsystem=ejb3,message-driven-bean=TargetConsumer");
log.info("Stopped jms delivery");
}
private void stopJmsDelivery(String name) {
try {
MBeanServer s = ManagementFactory.getPlatformMBeanServer();
ObjectName n = ObjectName.getInstance(name);
s.invoke(n, "stopDelivery", null, null);
} catch (Exception e) {
log.error(STOPPING_JMS_DELIVERY_FAILED_FOR + " exception: ", e);
} catch (Throwable throwable) { // NOSONAR catch also throwable since Exception is not enough in all cases.
log.error(STOPPING_JMS_DELIVERY_FAILED_FOR + " throwable: ", throwable);
}
}
This part of code is in "main.ear"."admin.war"
. There are several consumer classes in the same EAR and I can terminated them normally. But the last consumer class is in another.war
. If I try to stop it , NoClassDefException
is thrown. However I can stop it in JBoss EAP Management Console, which means the path is correct, and stopDelivery()
method is the right method to invoke.
Both main.ear
and another.war
are deployed in RedHat JBoss EAP 6.4 but separately.
main.ear
|
-- admin.war
another.war
To fix the NoClassDefException
, in the pom.xml
of module admin
, I introduce the another
module as dependency:
<dependency>
<groupId>com.example</groupId>
<artifactId>another</artifactId>
<classifier>classes</classifier> <!-- so to use `another-0.0.1-SNAPSHOT-classes.jar` -->
<version>${project.version}</version>
<scope>compile</scope> <!-- if put "provided", classes will not be packaged into `admin.war` and NoClassDefException -->
</dependency>
The compilation works, but when launching, this error happens:
ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) - MSC000001: Failed to start service
jboss.deployment.subunit."main.ear"."admin.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."main.ear"."admin.war".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of subdeployment "admin.war" of deployment "main.ear"
2024-06-05T11:49:58.929345566Z at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:184) [jboss-as-server-7.5.23.Final-redhat-00002.jar:7.5.23.Final-redhat-00002]
2024-06-05T11:49:58.929351032Z at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2064) [jboss-msc-1.1.7.SP1-redhat-1.jar:1.1.7.SP1-redhat-1]
2024-06-05T11:49:58.929354483Z at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1987) [jboss-msc-1.1.7.SP1-redhat-1.jar:1.1.7.SP1-redhat-1]
2024-06-05T11:49:58.929357898Z at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_372]
2024-06-05T11:49:58.929373706Z at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_372]
2024-06-05T11:49:58.929377514Z at java.lang.Thread.run(Thread.java:750) [rt.jar:1.8.0_372]
2024-06-05T11:49:58.929381166Z Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011232: Only one JAX-RS Application Class allowed. com.example.another.RestApplication com.example.admin.AdminApplication
2024-06-05T11:49:58.929384994Z at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:206)
2024-06-05T11:49:58.929402844Z at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)
2024-06-05T11:49:58.929406465Z at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:177) [jboss-as-server-7.5.23.Final-redhat-00002.jar:7.5.23.Final-redhat-00002]
2024-06-05T11:49:58.929410104Z ... 5 more
2024-06-05T11:49:58.929413220Z
How can I:
- avoid putting class
RestApplication
into theanother-0.0.1-SNAPSHOT-classes.jar
while listing it as compiled scope dependency foradmin.war
- meanwhile, make sure the original
RestApplication
endpoint deployed inanother.war
works normally?
I tried to use <type>war</type>
, but soon I found out that I shouldn’t deploy the same WAR twice, outside and inside the main.ear
.