Reputation: 301
I'm using the artemis-junit
dependency
testImplementation("org.apache.activemq:artemis-junit")
with Spring Boot 2+, and I have 2 JMS listeners with the following configuration:
destination = "my.topic"
clientId = "sharedApp1"
subscription = "mySharedSub"
durable = "true"
shared = "true"
I want to verify that shared subscription work but when I run the JUnit test the second listen throws
ActiveMQDuplicateMetaDataException[errorType=DUPLICATE_METADATA message=AMQ229035: Metadata jms-client-id=sharedApp1 had been set already]
stack-trace:
javax.jms.JMSException: Failed to create session factory
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:886) ~[artemis-jms-client-2.13.0.jar:2.13.0]
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:299) ~[artemis-jms-client-2.13.0.jar:2.13.0]
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:294) ~[artemis-jms-client-2.13.0.jar:2.13.0]
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196) ~[spring-jms-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:412) ~[spring-jms-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.jms.listener.AbstractJmsListeningContainer.establishSharedConnection(AbstractJmsListeningContainer.java:380) ~[spring-jms-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer.establishSharedConnection(DefaultMessageListenerContainer.java:818) ~[spring-jms-5.2.7.RELEASE.jar:5.2.7.RELEASE]
Is this by design (developer aid), as I'm running in the same JVM? or I'm doing something wrong?
Upvotes: 0
Views: 617
Reputation: 11
It seems to me that you are running the test inside the same JVM and is not possible due to the following validation (org.apache.activemq.artemis.jms.client.ActiveMQConnection):
private void validateClientID(ClientSession validateSession, String clientID)
throws InvalidClientIDException, ActiveMQException {
try {
validateSession.addUniqueMetaData(JMS_SESSION_CLIENT_ID_PROPERTY, clientID);
} catch (ActiveMQException e) {
if (e.getType() == ActiveMQExceptionType.DUPLICATE_METADATA) {
throw new InvalidClientIDException("clientID=" + clientID + " was already set into another connection");
} else {
throw e;
}
}
}
Upvotes: 1
Reputation: 35162
The error is by design. It's a violation of the JMS specification to have multiple concurrent JMS clients using the same client ID. Section 6.1.2 of the JMS 2 specification says this:
The purpose of client identifier is to associate a connection and its objects with a state maintained on behalf of the client by a provider. By definition, the client state identified by a client identifier can be ‘in use’ by only one client at a time. A JMS provider must prevent concurrently executing clients from using it.
Keep in mind that the client ID is optional for JMS 2 shared durable subscriptions. Section 4.2.2 of the JMS 2 specification states:
A shared durable subscription is identified by name and an optional client identifier, and may have several consumer objects consuming messages from it.
Upvotes: 1