ARTEMIS-4914 clarify docs on core + client ID

This commit also adds a couple of tests to verify the documented
behavior works.
This commit is contained in:
Justin Bertram 2024-07-09 10:33:53 -05:00 committed by Timothy Bish
parent b8a9d626cd
commit 0277c6498e
3 changed files with 99 additions and 21 deletions

View File

@ -22,7 +22,7 @@ import java.util.function.Predicate;
public class ActiveMQFilterPredicate<T> implements Predicate<T> {
enum Operation {
public enum Operation {
CONTAINS, NOT_CONTAINS, EQUALS, GREATER_THAN, LESS_THAN;
}

View File

@ -74,21 +74,20 @@ Blocking on each messages sent is costly since it requires a network round trip
By not blocking and receiving send acknowledgements asynchronously you can create true end to end asynchronous systems which is not possible using the standard JMS API.
For more information on this advanced feature please see the section xref:send-guarantees.adoc#guarantees-of-sends-and-commits[Guarantees of sends and commits].
==== Identifying your session for management and debugging
==== Identifying your client application for management and debugging
Assigning IDs to your core sessions can help you with monitoring and debugging the cluster using the xref:management-console.adoc#management-console[management console].
Assigning IDs to your core session can help you with monitoring and debugging using the xref:management-console.adoc#management-console[management console], e.g.:
[,java]
----
ClientSession session;
// ...
session.addMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY, "jms-client-id");
session.addMetaData("jms-client-id", "my-session");
ServerLocator locator = ...
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession(null, null, false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize(), "my-client-id");
----
Such ID will then appear in the *Client ID* column under the *Connections*, *Consumers* and *Producers* tabs.
The value `my-client-id` will then appear in the *Client ID* column under the *Connections*, *Consumers*, and *Producers* tabs.
If you are using the JMS API, the `setClientID` would give you the same effect.
If you are using the JMS API then `setClientID` would give you the same effect.
=== ClientConsumer

View File

@ -16,16 +16,6 @@
*/
package org.apache.activemq.artemis.tests.integration.management;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
@ -36,6 +26,7 @@ import javax.jms.Topic;
import javax.jms.TopicSubscriber;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
@ -95,6 +86,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.management.impl.view.predicate.ActiveMQFilterPredicate;
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;
@ -144,7 +136,16 @@ import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
@ExtendWith(ParameterizedTestExtension.class)
public class ActiveMQServerControlTest extends ManagementTestBase {
@ -4541,6 +4542,84 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
}
@TestTemplate
public void testListConnectionsCoreClientID() throws Exception {
final String clientId = RandomUtil.randomString();
SimpleString queueName1 = SimpleString.of("my_queue_one");
SimpleString addressName1 = SimpleString.of("my_address_one");
ActiveMQServerControl serverControl = createManagementControl();
server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
if (legacyCreateQueue) {
server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
} else {
server.createQueue(QueueConfiguration.of(queueName1).setAddress(addressName1).setRoutingType(RoutingType.ANYCAST).setDurable(false));
}
ClientSessionFactoryImpl csf = null;
try (ServerLocator locator = createInVMNonHALocator()) {
csf = (ClientSessionFactoryImpl) createSessionFactory(locator);
csf.createSession(null, null, false, true, true, locator.isPreAcknowledge(), locator.getAckBatchSize(), clientId);
String filterString = createJsonFilter(ConnectionField.CLIENT_ID.getName(), ActiveMQFilterPredicate.Operation.EQUALS.toString(), clientId);
String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
assertEquals(1, array.size(), "number of connections returned from query");
JsonObject jsonConnection = array.getJsonObject(0);
assertEquals(clientId, jsonConnection.getString(ConnectionField.CLIENT_ID.getName()));
} finally {
if (csf != null) {
csf.close();
}
}
}
@TestTemplate
public void testListConnectionsCoreClientIDLegacy() throws Exception {
final String clientId = RandomUtil.randomString();
SimpleString queueName1 = SimpleString.of("my_queue_one");
SimpleString addressName1 = SimpleString.of("my_address_one");
ActiveMQServerControl serverControl = createManagementControl();
server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
if (legacyCreateQueue) {
server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
} else {
server.createQueue(QueueConfiguration.of(queueName1).setAddress(addressName1).setRoutingType(RoutingType.ANYCAST).setDurable(false));
}
ClientSessionFactoryImpl csf = null;
try (ServerLocator locator = createInVMNonHALocator()) {
csf = (ClientSessionFactoryImpl) createSessionFactory(locator);
ClientSession session = csf.createSession();
session.addUniqueMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY, "");
session.addUniqueMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, clientId);
String filterString = createJsonFilter(ConnectionField.CLIENT_ID.getName(), ActiveMQFilterPredicate.Operation.EQUALS.toString(), clientId);
String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
assertEquals(1, array.size(), "number of connections returned from query");
JsonObject jsonConnection = array.getJsonObject(0);
assertEquals(clientId, jsonConnection.getString(ConnectionField.CLIENT_ID.getName()));
} finally {
if (csf != null) {
csf.close();
}
}
}
@TestTemplate
public void testListConnectionsJmsClientID() throws Exception {
final String clientId = RandomUtil.randomString();
@ -4550,7 +4629,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0");
try (Connection c = cf.createConnection()) {
c.setClientID(clientId);
String filterString = createJsonFilter(ConnectionField.CLIENT_ID.getName(), "EQUALS", clientId);
String filterString = createJsonFilter(ConnectionField.CLIENT_ID.getName(), ActiveMQFilterPredicate.Operation.EQUALS.toString(), clientId);
String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);