From 614b5cb32f8df9cd2824fdfe3b1e2cbdb44f2d6a Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Sat, 13 Apr 2024 22:57:02 -0500 Subject: [PATCH] ARTEMIS-1769 return JMS Session's ClientID via JMX --- .../management/impl/view/SessionView.java | 5 +++- .../management/ActiveMQServerControlTest.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java index fedc96f44b..182d84285e 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/SessionView.java @@ -46,7 +46,8 @@ public class SessionView extends ActiveMQAbstractView { .add(SessionField.CREATION_TIME.getName(), new Date(session.getCreationTime()).toString()) .add(SessionField.CONSUMER_COUNT.getName(), session.getConsumerCount()) .add(SessionField.PRODUCER_COUNT.getName(), session.getProducerCount()) - .add(SessionField.CONNECTION_ID.getName(), session.getConnectionID().toString()); + .add(SessionField.CONNECTION_ID.getName(), session.getConnectionID().toString()) + .add(SessionField.CLIENT_ID.getName(), session.getRemotingConnection().getClientID()); return obj; } @@ -69,6 +70,8 @@ public class SessionView extends ActiveMQAbstractView { return session.getProducerCount(); case CONNECTION_ID: return session.getConnectionID(); + case CLIENT_ID: + return session.getRemotingConnection().getClientID(); default: throw new IllegalArgumentException("Unsupported field, " + fieldName); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java index c7ad640605..be1cb95741 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java @@ -82,6 +82,7 @@ import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration; import org.apache.activemq.artemis.core.management.impl.view.ConnectionField; import org.apache.activemq.artemis.core.management.impl.view.ConsumerField; import org.apache.activemq.artemis.core.management.impl.view.ProducerField; +import org.apache.activemq.artemis.core.management.impl.view.SessionField; import org.apache.activemq.artemis.core.messagecounter.impl.MessageCounterManagerImpl; import org.apache.activemq.artemis.core.persistence.OperationContext; import org.apache.activemq.artemis.core.persistence.config.PersistedDivertConfiguration; @@ -4330,6 +4331,29 @@ public class ActiveMQServerControlTest extends ManagementTestBase { } } + @Test + public void testListSessionsJmsClientID() throws Exception { + final String clientId = RandomUtil.randomString(); + + ActiveMQServerControl serverControl = createManagementControl(); + + ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0"); + try (Connection c = cf.createConnection()) { + c.setClientID(clientId); + c.createSession(); + String filter = createJsonFilter(SessionField.CLIENT_ID.getName(), "EQUALS", clientId); + String json = serverControl.listSessions(filter, 1, 50); + System.out.println(json); + JsonObject sessions = JsonUtil.readJsonObject(json); + JsonArray array = (JsonArray) sessions.get("data"); + + Assert.assertEquals("number of sessions returned from query", 2, array.size()); + JsonObject jsonSession = array.getJsonObject(0); + + Assert.assertEquals("wrong client ID returned", clientId, jsonSession.getString(SessionField.CLIENT_ID.getName())); + } + } + @RetryMethod(retries = 2) // the list of connections eventually comes from a hashmap on a different order. Which is fine but makes the test fail. a Retry is ok @Test public void testListConnections() throws Exception {