ARTEMIS-1769 return JMS Session's ClientID via JMX

This commit is contained in:
Justin Bertram 2024-04-13 22:57:02 -05:00
parent fc6f0ee9ec
commit 614b5cb32f
2 changed files with 28 additions and 1 deletions

View File

@ -46,7 +46,8 @@ public class SessionView extends ActiveMQAbstractView<ServerSession> {
.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<ServerSession> {
return session.getProducerCount();
case CONNECTION_ID:
return session.getConnectionID();
case CLIENT_ID:
return session.getRemotingConnection().getClientID();
default:
throw new IllegalArgumentException("Unsupported field, " + fieldName);
}

View File

@ -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 {