mirror of
https://github.com/apache/activemq-artemis.git
synced 2025-02-28 22:39:27 +00:00
ARTEMIS-1921 setting client ID on core JMS should be reflected in broker RemotingConnection
This commit is contained in:
parent
31243b1023
commit
791630fa86
@ -16,16 +16,15 @@
|
||||
*/
|
||||
package org.apache.activemq.artemis.core.management.impl.view;
|
||||
|
||||
import org.apache.activemq.artemis.json.JsonObjectBuilder;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.ConnectionFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.json.JsonObjectBuilder;
|
||||
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
import org.apache.activemq.artemis.utils.StringUtil;
|
||||
@ -52,14 +51,9 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
|
||||
|
||||
List<ServerSession> sessions = server.getSessions(connection.getID().toString());
|
||||
Set<String> users = new TreeSet<>();
|
||||
String jmsSessionClientID = null;
|
||||
for (ServerSession session : sessions) {
|
||||
String username = session.getUsername() == null ? "" : session.getUsername();
|
||||
users.add(username);
|
||||
//for the special case for JMS
|
||||
if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) {
|
||||
jmsSessionClientID = session.getMetaData("jms-client-id");
|
||||
}
|
||||
}
|
||||
|
||||
return JsonLoader.createObjectBuilder()
|
||||
@ -69,7 +63,7 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
|
||||
.add(ConnectionField.CREATION_TIME.getName(), new Date(connection.getCreationTime()).toString())
|
||||
.add(ConnectionField.IMPLEMENTATION.getName(), toString(connection.getClass().getSimpleName()))
|
||||
.add(ConnectionField.PROTOCOL.getName(), toString(connection.getProtocolName()))
|
||||
.add(ConnectionField.CLIENT_ID.getName(), toString(connection.getClientID() != null ? connection.getClientID() : jmsSessionClientID))
|
||||
.add(ConnectionField.CLIENT_ID.getName(), toString(connection.getClientID()))
|
||||
.add(ConnectionField.LOCAL_ADDRESS.getName(), toString(connection.getTransportLocalAddress()))
|
||||
.add(ConnectionField.SESSION_COUNT.getName(), sessions.size());
|
||||
}
|
||||
|
@ -16,15 +16,14 @@
|
||||
*/
|
||||
package org.apache.activemq.artemis.core.management.impl.view;
|
||||
|
||||
import org.apache.activemq.artemis.core.management.impl.ActiveMQServerControlImpl;
|
||||
import org.apache.activemq.artemis.json.JsonObjectBuilder;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
||||
import org.apache.activemq.artemis.core.management.impl.ActiveMQServerControlImpl;
|
||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.ConsumerFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ServerConsumer;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.json.JsonObjectBuilder;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
|
||||
public class ConsumerView extends ActiveMQAbstractView<ServerConsumer> {
|
||||
@ -57,16 +56,10 @@ public class ConsumerView extends ActiveMQAbstractView<ServerConsumer> {
|
||||
return null;
|
||||
}
|
||||
|
||||
String consumerClientID = consumer.getConnectionClientID();
|
||||
if (consumerClientID == null && session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) {
|
||||
//for the special case for JMS
|
||||
consumerClientID = session.getMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY);
|
||||
}
|
||||
|
||||
JsonObjectBuilder obj = JsonLoader.createObjectBuilder()
|
||||
.add(ConsumerField.ID.getName(), toString(consumer.getSequentialID()))
|
||||
.add(ConsumerField.SESSION.getName(), toString(consumer.getSessionName()))
|
||||
.add(ConsumerField.CLIENT_ID.getName(), toString(consumerClientID))
|
||||
.add(ConsumerField.CLIENT_ID.getName(), toString(consumer.getConnectionClientID()))
|
||||
.add(ConsumerField.USER.getName(), toString(session.getUsername()))
|
||||
.add(ConsumerField.VALIDATED_USER.getName(), toString(session.getValidatedUser()))
|
||||
.add(ConsumerField.PROTOCOL.getName(), toString(consumer.getConnectionProtocolName()))
|
||||
|
@ -16,13 +16,11 @@
|
||||
*/
|
||||
package org.apache.activemq.artemis.core.management.impl.view;
|
||||
|
||||
import org.apache.activemq.artemis.json.JsonObjectBuilder;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
||||
import org.apache.activemq.artemis.core.management.impl.view.predicate.ProducerFilterPredicate;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ServerProducer;
|
||||
import org.apache.activemq.artemis.core.server.ServerSession;
|
||||
import org.apache.activemq.artemis.json.JsonObjectBuilder;
|
||||
import org.apache.activemq.artemis.utils.JsonLoader;
|
||||
|
||||
public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
|
||||
@ -51,17 +49,11 @@ public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
|
||||
return null;
|
||||
}
|
||||
|
||||
String sessionClientID = session.getRemotingConnection().getClientID();
|
||||
//for the special case for JMS
|
||||
if (sessionClientID == null && session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) {
|
||||
sessionClientID = session.getMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY);
|
||||
}
|
||||
|
||||
JsonObjectBuilder obj = JsonLoader.createObjectBuilder()
|
||||
.add(ProducerField.ID.getName(), toString(producer.getID()))
|
||||
.add(ProducerField.NAME.getName(), toString(producer.getName()))
|
||||
.add(ProducerField.SESSION.getName(), toString(session.getName()))
|
||||
.add(ProducerField.CLIENT_ID.getName(), toString(sessionClientID))
|
||||
.add(ProducerField.CLIENT_ID.getName(), toString(session.getRemotingConnection().getClientID()))
|
||||
.add(ProducerField.USER.getName(), toString(session.getUsername()))
|
||||
.add(ProducerField.VALIDATED_USER.getName(), toString(session.getValidatedUser()))
|
||||
.add(ProducerField.PROTOCOL.getName(), toString(session.getRemotingConnection().getProtocolName()))
|
||||
|
@ -46,6 +46,7 @@ import org.apache.activemq.artemis.api.core.Pair;
|
||||
import org.apache.activemq.artemis.api.core.QueueConfiguration;
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientSession;
|
||||
import org.apache.activemq.artemis.api.core.management.CoreNotificationType;
|
||||
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
|
||||
import org.apache.activemq.artemis.core.exception.ActiveMQXAException;
|
||||
@ -2059,6 +2060,9 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
|
||||
return false;
|
||||
} else {
|
||||
addMetaData(key, data);
|
||||
if (key.equals(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY)) {
|
||||
remotingConnection.setClientID(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.jms.multiprotocol;
|
||||
|
||||
import org.apache.activemq.artemis.tests.util.RandomUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JMSClientIDTest extends MultiprotocolJMSClientTestSupport {
|
||||
|
||||
@Test
|
||||
public void testAMQPJmsClientIdSetOnBroker() throws Exception {
|
||||
String testClientId = RandomUtil.randomString();
|
||||
createConnection(testClientId);
|
||||
assertEquals(testClientId, server.getRemotingService().getConnections().iterator().next().getClientID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenWireJmsClientIdSetOnBroker() throws Exception {
|
||||
String testClientId = RandomUtil.randomString();
|
||||
createOpenWireConnection(testClientId);
|
||||
assertEquals(testClientId, server.getRemotingService().getConnections().iterator().next().getClientID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoreJmsClientIdSetOnBroker() throws Exception {
|
||||
String testClientId = RandomUtil.randomString();
|
||||
createCoreConnection(testClientId);
|
||||
assertEquals(testClientId, server.getRemotingService().getConnections().iterator().next().getClientID());
|
||||
}
|
||||
}
|
@ -341,7 +341,6 @@ public abstract class MultiprotocolJMSClientTestSupport extends ActiveMQTestBase
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
protected String getBrokerCoreJMSConnectionString() {
|
||||
try {
|
||||
String uri = "tcp://127.0.0.1:" + PORT;
|
||||
@ -364,6 +363,10 @@ public abstract class MultiprotocolJMSClientTestSupport extends ActiveMQTestBase
|
||||
return createCoreConnection(getBrokerCoreJMSConnectionString(), null, null, null, start);
|
||||
}
|
||||
|
||||
protected Connection createCoreConnection(String clientId) throws JMSException {
|
||||
return createCoreConnection(getBrokerCoreJMSConnectionString(), null, null, clientId, true);
|
||||
}
|
||||
|
||||
protected Connection createCoreConnection(String connectionString,
|
||||
String username,
|
||||
String password,
|
||||
@ -410,6 +413,10 @@ public abstract class MultiprotocolJMSClientTestSupport extends ActiveMQTestBase
|
||||
return createOpenWireConnection(getBrokerOpenWireJMSConnectionString(), null, null, null, start);
|
||||
}
|
||||
|
||||
protected Connection createOpenWireConnection(String clientId) throws JMSException {
|
||||
return createOpenWireConnection(getBrokerOpenWireJMSConnectionString(), null, null, clientId, true);
|
||||
}
|
||||
|
||||
protected Connection createOpenWireConnection(String connectionString,
|
||||
String username,
|
||||
String password,
|
||||
|
@ -79,6 +79,7 @@ import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.Configuration;
|
||||
import org.apache.activemq.artemis.core.config.brokerConnectivity.BrokerConnectConfiguration;
|
||||
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.messagecounter.impl.MessageCounterManagerImpl;
|
||||
@ -4452,31 +4453,15 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListConnectionsClientID() throws Exception {
|
||||
SimpleString queueName1 = new SimpleString("my_queue_one");
|
||||
SimpleString addressName1 = new SimpleString("my_address_one");
|
||||
public void testListConnectionsJmsClientID() throws Exception {
|
||||
final String clientId = RandomUtil.randomString();
|
||||
|
||||
ActiveMQServerControl serverControl = createManagementControl();
|
||||
|
||||
server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST));
|
||||
if (legacyCreateQueue) {
|
||||
server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false);
|
||||
} else {
|
||||
server.createQueue(new QueueConfiguration(queueName1).setAddress(addressName1).setRoutingType(RoutingType.ANYCAST).setDurable(false));
|
||||
}
|
||||
|
||||
ClientSessionFactoryImpl csf = null;
|
||||
|
||||
// create some consumers
|
||||
try (ServerLocator locator = createInVMNonHALocator()) {
|
||||
//sleep as test compares creationTime
|
||||
csf = (ClientSessionFactoryImpl) createSessionFactory(locator);
|
||||
ClientSession session1_c1 = csf.createSession();
|
||||
ClientSession session2_c1 = csf.createSession();
|
||||
session1_c1.addMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY, "");
|
||||
session1_c1.addMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, "MYClientID");
|
||||
|
||||
String filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1");
|
||||
ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0");
|
||||
try (Connection c = cf.createConnection()) {
|
||||
c.setClientID(clientId);
|
||||
String filterString = createJsonFilter(ConnectionField.CLIENT_ID.getName(), "EQUALS", clientId);
|
||||
String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50);
|
||||
JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString);
|
||||
JsonArray array = (JsonArray) connectionsAsJsonObject.get("data");
|
||||
@ -4484,12 +4469,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
|
||||
Assert.assertEquals("number of connections returned from query", 1, array.size());
|
||||
JsonObject jsonConnection = array.getJsonObject(0);
|
||||
|
||||
//check all fields
|
||||
Assert.assertEquals("clientID", "MYClientID", jsonConnection.getString("clientID"));
|
||||
} finally {
|
||||
if (csf != null) {
|
||||
csf.close();
|
||||
}
|
||||
Assert.assertEquals("wrong client ID returned", clientId, jsonConnection.getString(ConnectionField.CLIENT_ID.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user