Skip to content

Commit 90e3db6

Browse files
brusdevjbertram
authored andcommitted
ARTEMIS-5976 Pass clientID to session creation in ActiveMQResourceAdapter
The ActiveMQResourceAdapter.createSession() method was not passing the clientID parameter when creating sessions via ClientSessionFactory, resulting in remoting connection without the clientID property set on the server side.
1 parent 1ace59f commit 90e3db6

2 files changed

Lines changed: 68 additions & 5 deletions

File tree

artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQResourceAdapter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,20 +1030,20 @@ public ClientSession createSession(final ClientSessionFactory parameterFactory,
10301030
// If transacted we need to send the ack flush as soon as possible as if any transaction times out, we need
10311031
// the ack on the server already
10321032
if (useLocalTx) {
1033-
result = parameterFactory.createSession(user, pass, false, false, false, false, 0);
1033+
result = parameterFactory.createSession(user, pass, false, false, false, false, 0, getClientID());
10341034
} else {
1035-
result = parameterFactory.createSession(user, pass, true, false, false, false, 0);
1035+
result = parameterFactory.createSession(user, pass, true, false, false, false, 0, getClientID());
10361036
}
10371037
} else {
10381038
if (preAck != null && preAck) {
1039-
result = parameterFactory.createSession(user, pass, false, true, true, true, -1);
1039+
result = parameterFactory.createSession(user, pass, false, true, true, true, -1, getClientID());
10401040
} else {
10411041
// only auto ack and dups ok are supported
10421042
result = switch (ackMode) {
1043-
case Session.AUTO_ACKNOWLEDGE -> parameterFactory.createSession(user, pass, false, true, true, false, 0);
1043+
case Session.AUTO_ACKNOWLEDGE -> parameterFactory.createSession(user, pass, false, true, true, false, 0, getClientID());
10441044
case Session.DUPS_OK_ACKNOWLEDGE -> {
10451045
int actDupsOkBatchSize = dupsOkBatchSize != null ? dupsOkBatchSize : ActiveMQClient.DEFAULT_ACK_BATCH_SIZE;
1046-
yield parameterFactory.createSession(user, pass, false, true, true, false, actDupsOkBatchSize);
1046+
yield parameterFactory.createSession(user, pass, false, true, true, false, actDupsOkBatchSize, getClientID());
10471047
}
10481048
default -> throw new IllegalArgumentException("Invalid ackmode: " + ackMode);
10491049
};

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/ResourceAdapterTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,69 @@ public void testConnectionFactoryPropertiesApplyToRecoveryConfig() throws Except
891891

892892
}
893893

894+
@Test
895+
public void testClientIDPassedToSessionWithUseLocalTx() throws Exception {
896+
testClientIDPassedToSession("testClientID", ra -> ra.setUseLocalTx(true), spec -> { }, false);
897+
}
898+
899+
@Test
900+
public void testClientIDPassedToSessionWithDeliveryTransacted() throws Exception {
901+
testClientIDPassedToSession("testClientIDTransacted", ra -> { }, spec -> { }, true);
902+
}
903+
904+
@Test
905+
public void testClientIDPassedToSessionWithPreAck() throws Exception {
906+
testClientIDPassedToSession("testClientIDPreAck", ra -> ra.setPreAcknowledge(true), spec -> { }, false);
907+
}
908+
909+
@Test
910+
public void testClientIDPassedToSessionWithDupsOkAck() throws Exception {
911+
testClientIDPassedToSession("testClientIDDupsOk",
912+
ra -> ra.setDupsOKBatchSize(100),
913+
spec -> spec.setAcknowledgeMode("Dups-ok-acknowledge"),
914+
false);
915+
}
916+
917+
@Test
918+
public void testClientIDPassedToSessionWithAutoAck() throws Exception {
919+
testClientIDPassedToSession("testClientIDAutoAck",
920+
ra -> { },
921+
spec -> spec.setAcknowledgeMode("Auto-acknowledge"),
922+
false);
923+
}
924+
925+
private void testClientIDPassedToSession(String clientID,
926+
java.util.function.Consumer<ActiveMQResourceAdapter> raConfigurator,
927+
java.util.function.Consumer<ActiveMQActivationSpec> specConfigurator,
928+
boolean deliveryTransacted) throws Exception {
929+
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
930+
ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
931+
ra.setClientID(clientID);
932+
raConfigurator.accept(ra);
933+
ra.start(new BootstrapContext());
934+
935+
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
936+
spec.setResourceAdapter(ra);
937+
spec.setUseJNDI(false);
938+
spec.setDestinationType("javax.jms.Queue");
939+
spec.setDestination(MDBQUEUE);
940+
specConfigurator.accept(spec);
941+
942+
CountDownLatch latch = new CountDownLatch(1);
943+
DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
944+
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, deliveryTransacted);
945+
946+
ra.endpointActivation(endpointFactory, spec);
947+
948+
// Verify the clientID is set on the server-side remoting connection
949+
assertFalse(server.getRemotingService().getConnections().isEmpty());
950+
assertTrue(server.getRemotingService().getConnections().stream().allMatch(
951+
remotingConnection -> clientID.equals(remotingConnection.getClientID())));
952+
953+
ra.stop();
954+
assertTrue(endpoint.released);
955+
}
956+
894957
@Override
895958
public boolean useSecurity() {
896959
return false;

0 commit comments

Comments
 (0)