Skip to content

Commit

Permalink
ARTEMIS-1769 return JMS Session's ClientID via JMX
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Apr 27, 2024
1 parent fc6f0ee commit 614b5cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public JsonObjectBuilder toJson(ServerSession session) {
.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;
}

Expand All @@ -69,6 +70,8 @@ public Object getField(ServerSession session, String fieldName) {
return session.getProducerCount();
case CONNECTION_ID:
return session.getConnectionID();
case CLIENT_ID:
return session.getRemotingConnection().getClientID();
default:
throw new IllegalArgumentException("Unsupported field, " + fieldName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
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;
Expand Down Expand Up @@ -4330,6 +4331,29 @@ public void testListSessions() throws Exception {
}
}

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

0 comments on commit 614b5cb

Please sign in to comment.